CodesJava

Easy learning with example program codes

Angularjs custom filters tutorial


Angularjs custom filters:

AngularJS provides the facility to create the custom filters. Custom filters are created using “filter” function.

Example Explanation:

The ng-app directive initializes the application. We create a testFilter which reverse the string and capitalize the first letter.

Example:

<!DOCTYPE html>
<html>
<script 
 src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
 
<body>
 <div ng-app="testApp" ng-controller="appCtrl">
   Welcome to {{ name | testFilter }}
 </div>
 
 <script>
   var app = angular.module('testApp', []);
      app.controller('appCtrl', function($scope) {
          $scope.name = "tutorialspointexamples"
       });
 
    app.filter('testFilter',function(){
      return function( str ) {
        var revStr = str.split('').reverse();
        return revStr[0].toUpperCase() + revStr.join('').slice(1);
      }
   });
</script>
</body>
</html>

Try it:

JS Bin on jsbin.com



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki