AngularJS orderby integer field not working properly

后端 未结 6 1332
無奈伤痛
無奈伤痛 2021-01-02 05:45

I just took the simplest demo from http://docs.angularjs.org/api/ng.filter:orderBy and just change the value of age to have different number of digit. It stop working as it

6条回答
  •  执念已碎
    2021-01-02 06:33

    you have to convert age to type Number to make to orderBy to work as it should.

    Add to your controller to sort String age as float:

       angular.forEach($scope.friends, function (friend) {
        friend.age = parseFloat(friend.age);
       });
    

    It should work,

    See PLunker

提交回复
热议问题