Filter in AngularJs


Here give you detailed example how to use filters in angularjs.

Filter are used to  modify and transform data and angularjs provide filters to transform data.
Here we give the number of filter which are commonly used in angularjs.


Filter format the value of an expression for display to the user. They can be used in view templates, controller or services. AngularJs comes with a collection of built- in filters, but it is easy to define your own as well. It is used to format input value or to filter an array with is given matching input criteria.. 




Syntax:-  {{ expression | filter }}

 {{ expression | filter1 } filter2 | ... }}
  • currency Format a number to a currency format.
  • date Format a date to a specified format.
  • filter Select a subset of items from an array.
  • json Format an object to a JSON string.
  • limitTo Limits an array/string, into a specified number of elements/characters.
  • lowercase Format a string to lower case.
  • number Format a number to a string.
  • orderBy Orders an array by an expression.
  • uppercase Format a string to upper case.

   Angular JS filter used with pipe charcter ||    



The uppercase  filter format strings to upper case:

<p>The name is {{ lastName | uppercase }}</p>

The lowercase  filter format strings to upper case:

<p>The name is {{ lastName | lowercase }}</p>

The orderby filter format strings to upper case:

 <li ng-repeat="x in names | orderBy:'country'"> {{ x.name + ', ' + x.country }} </li>

The currency filter format strings to upper case:

 <p>The name is {{ money| currency }}</p>

The filter format strings to upper case:

 <li ng-repeat="x in names | filter:'country'"> {{ x.name + ', ' + x.country }} </li>

The limitTo filter format strings to upper case:

 <li ng-repeat="x in names | limitTo:'5'">
 {{ x.name + ', ' + x.country }}
 </li>

Hope you like the post . Please share and comment the queries below or customer care section.

Thanks,

Post a Comment

0 Comments