javascript - Getting error while sorting records in descending order by Id with orderby clause in Angular js -
i trying display records in descending order of id
property.
but getting error below in browser console:
[orderby:notarray] expected array received: {"name":"abc","emailid":"abc@yahoo.com","salary":4000}
this code:
<table> <tr> <td ng-repeat="item in user " ng-if="$odd" > </td> </tr> </table> <table> <tr> <td ng-repeat="item in user " ng-if="$even" > </td> </tr> </table> <tr ng-repeat="item in user | orderby: '-id' "> </td> function displaydata() { myservice.getlist().then( function (data) { $scope.user = data }, function (reason) { }) }
json output:
[ { "id":5, "name": "abc", "emailid": "abc@yaoo.com", "salary" : 4000 }, { "id":11, "name": "yyy", "emailid": "abc@yaoo.com", "salary" : 4000 }, { "id":7, "name": "iii", "emailid": "abc@yaoo.com", "salary" : 4000 }, {' "id":3, "name": "www", "emailid":"abc@yaoo.com", "salary" : 4000 } ]
the problem assignment:
function displaydata() { myservice.getlist().then( function (data) { $scope.user = data }, function (reason) { }) }
function .then()
returns promise object allow chaining: .then().then()
, , because returns object that's why receive notarray error.
to avoid reference error can specify $scope.user empty arrray earlier, assign results it.
function displaydata() { $scope.user = []; myservice.getlist().then( function (data) { $scope.user = data }, function (reason) { }) }
this worked successfully...
Comments
Post a Comment