AngularJS Use points

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.