AngularJS-$filter-1

 

$filter is a service used to format the expression. In this example, we need to inject controller with $filter service. We are assigning learnkode to originalText variable and the $filter('uppercase')($scope.originalText) will convert learnKode to uppercase. $scope.originalText = 'learnkode'; $scope.filteredText = $filter('uppercase')($scope.originalText); See the code snippet:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="controllerName"> <h3>{{ originalText }}</h3> <h3>{{ filteredText }}</h3> </div> </body> </html> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', '$filter', function ($scope, $filter) { $scope.originalText = 'learnkode'; $scope.filteredText = $filter('uppercase')($scope.originalText); }]); </script>
Output