AngularJS provides filters to transform data:
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.
Example uppercase
Format a string to upper case.
<div ng-app="myApp" ng-controller="personCtrl">
<p>The name is {{ lastName | uppercase }}</p>
</div>
<p>The name is {{ lastName | uppercase }}</p>
</div>
Example lowercase
Format a string to lower case.
<div ng-app="myApp" ng-controller="personCtrl">
<p>The name is {{ lastName | lowercase }}</p>
</div>
<p>The name is {{ lastName | lowercase }}</p>
</div>
orderBy
Orders an array by an expression.
<div ng-app="myApp" ng-controller="namesCtrl">
<ul>
<li ng-repeat="x in names | orderBy:'country'">
{{ x.name + ', ' + x.country }}
</li>
</ul>
</div>
<ul>
<li ng-repeat="x in names | orderBy:'country'">
{{ x.name + ', ' + x.country }}
</li>
</ul>
</div>
currency
Format a number to a currency format.
<div ng-app="myApp" ng-controller="costCtrl">
<h1>Price: {{ price | currency }}</h1>
</div>
<h1>Price: {{ price | currency }}</h1>
</div>
filter
Select a subset of items from an array.
Example 1:
<div ng-app="myApp" ng-controller="namesCtrl">
<ul>
<li ng-repeat="x in names | filter : 'i'">
{{ x }}
</li>
</ul>
</div>
<ul>
<li ng-repeat="x in names | filter : 'i'">
{{ x }}
</li>
</ul>
</div>
Example 2:
<div ng-app="myApp" ng-controller="namesCtrl">
<p><input type="text" ng-model="test"></p>
<ul>
<li ng-repeat="x in names | filter : test">
{{ x }}
</li>
</ul>
</div>
<p><input type="text" ng-model="test"></p>
<ul>
<li ng-repeat="x in names | filter : test">
{{ x }}
</li>
</ul>
</div>
No comments:
Post a Comment