I use orderBy to sort my data in ng-repeat by is_important property & desc, like below:
<li ng-repeat="data in datas | orderBy:'-is_important'">{{data.id}}</li>
$scope.datas = [{"id":"1","is_important":"0"},
{"id":"2","is_important":"0"},
{"id":"3","is_important":"0"},
{"id":"4","is_important":"1"},
{"id":"5","is_important":"0"},
{"id":"6","is_important":"0"}];
At the beginning, the order show on the screen is correct
4
1
2
3
5
6
But when I change the is_important property
$scope.datas[3].is_important = 0;
$scope.datas[5].is_important = 1;
the result displayed by ng-repeat :
1
2
3
5
6
4
isn't same as my expected answer:
6
1
2
3
4
5
Why?
this is my code: http://jsbin.com/oMUSeHO/1/edit
Because in change method you set is_important to digit.
$scope.datas[3].is_important = 0;
$scope.datas[5].is_important = 1;
Change it as follows
$scope.datas[3].is_important = "0";
$scope.datas[5].is_important = "1";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With