AngularJS Summary of Use points:
1, writing format
The basic application format is:
Ng-repeat= "Item in ItemList | OrderBy:p1:p2 "
The parameter P1 can be a field name or a custom function, p2 refers to whether reverse is reversed, the default is False
Example:
Suppose there are $scope in the
var itemlist=[{id:201,name: ' abc ', Amount:100},{id:100,name: ' Zdb ', amount:100},
{id:10,name: ' xxx ', amount:200},{id:80,name: ' 231 ', amount:1020},
{id:50,name: ' PPP ', Amount:20},{id:1,name: ' HHH ', amount:1100}];
Sort by ID, inverted
Ng-repeat= "Item in ItemList | By: ' ID ': true '
2, custom sort:
The controller sets the custom function, the function accepts the parameter as the current item and needs to return a value that represents the order of the item
$scope. orderit=function(item) { if(item.name.indexOf (' h ') ===0)return 0 ; return 1;};
How to use:
Ng-repeat= "Item in ItemList | Orderby:orderit "
3, Multi-field sorting:
If the above method is not satisfied, it will sacrifice a skill! The order number also supports multi-field sorting by:
Ng-repeat= "Item in ItemList | Orderby:[orderit, ' name ', '-amount ')
Yes, the first parameter passes an array, which can be a custom function or field name, preceded by a "-", which represents an inverted sort.
AngularJS Use points