AngularJS Create custom display filter in AngularJS

In this AngularJS custom filter example you will learn how to create custom display filter in angularjs using filter method.

Here you can view the output of the example and you can also "try it yourself" by clicking on "Live Demo" button given at the bottom.

Syntax

var app = angular.module('app', []);
app.filter('pascalCase',function(){
	//write filter code here
});

Example Create custom display filter in AngularJS using filter method

<!DOCTYPE html>              
<html>              
<head> <!-- www.techstrikers.com -->               
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.1/angular.min.js"></script>               
    <meta charset="utf-8">              
    <title>AngularJS Create custom filter in AngularJS 
	using filter method Example</title>  
  <script>              
var app = angular.module('app', []); 
app.filter('pascalCase',function(){
	return function(value){
		var returnVal = ' ';
		var words = value.split(' ');
		words.forEach(function(item){
			if(returnVal)
				returnVal == ' ';
			else
				returnVal = '';
			returnVal += item.substr(0,1).toUpperCase() + 
			item.substr(1).toLowerCase() + ' ';
		});
	  return returnVal;
	};
});
    app.controller("ParentController", function ($scope) {      
    $scope.employees = [{    
        firstName:"jimi",    
        lastName:"scott",    
        jobTitle:"developer",    
        salary:20000,    
        phone:"345-333-7845"    
      },    
      {    
          firstName:"bailey",    
          lastName:"lee",    
          jobTitle:"lead",    
          salary:30000,    
          phone:"322-121-213"    
      },    
      {    
          firstName:"aura",    
          lastName:"martin",    
          jobTitle:"qa",    
          salary:35000,    
          phone:"322-333-0987"    
      },    
      {    
          firstName:"austin",    
          lastName:"williams",    
          jobTitle:"designer",    
          salary:20000,    
          phone:"322-265-2321"    
      }];  
      $scope.numLimit = 5;  
      $scope.numStart = 0;  
    });       
</script>              
</head>              
<body style="background-color:#DDE4E9;">              
  <fieldset style="background-color:#DDE4E9;">                          
<legend>AngulerJS Create custom filter in AngularJS using 
filter method Example</legend>       
  <div ng-app="app">       
    <div ng-controller="ParentController">    
      <ul ng-repeat="emp in employees | limitTo:numLimit:numStart">    
        <li>Name : {{ emp.firstName + ' ' + emp.lastName | pascalCase}}</li>    
        <li>Job Title : {{ emp.jobTitle | pascalCase}}</li>    
        <li>Salary : {{ emp.salary }}</li>    
        <li>Phone : {{ emp.phone }}</li>    
    </ul>    
  </div>      
</div>              
</div>              
 </fieldset>               
</body>              
</html>     

Try Now

More AngularJS Filter Examples

 
 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.