In front of the introduction Angularjs already a lot of, halfway due to work and all life chores, suspended for a long time. Here today will continue to Angularjs, this section we look at Angularjs filtration to filter.
In our development often need to display on the page to the user's information needs to be processed format, can be displayed to the user. such as time localization, or YYYY-MM-DD HH:MM:SS format, digital precision format, localization, name format and so on. In the ANGULARJS to provide us with the order called filter, so that we can easily do some of the functions of the column, Angularjs inside for us to provide a number of many built-in filter. And we can easily customize our domain filter.
The following example:
Html:
<center ng-app= "App" ng-
controller= "Test" >
num:<input ng-model= "num"/>
<br/>
{ {num | number}}
<br/>
{num | number:2}}
<br/>
name:<input ng-model= "Person.first"/>
< Br/> last
name:<input ng-model= "Person.last"/>
<br/>
Name: {{person | fullname}}
<br/>
Name: {{person | fullname: '--"}}
<br/>
name: {{person | fullname:" | Uppercase}}
</center>
Js:
function test ($scope) {
}
angular.module ("app", []). Controller ("test", test)
. Filter ("FullName", function () {
var filterfun = function (person, Sep) {
Sep = Sep | | " ";
person = Person | | {};
Person.first = Person.first | | "";
Person.last = Person.last | | "";
return Person.first + Sep + person.last;
};
return filterfun;
});
Jsfiddle Effect: http://jsfiddle.net/whitewolf/uCPPK/12/
In the example, the filter use of the number with ANGULARJS is first demonstrated. Again for our style how to create a angularjs filter. The implementation is simple. Angularjs makes it all natural to expand
Finally: Filters support chain style, how to PowerShell or other operating system shell language like the pipeline model, such as value | Filter1 | Filter2.