javascript - AngularJS sorting using JSON keys with spaces -
through angularjs application make calls api return json in following format:
[object, object] 0: object $$hashkey: "01" contact name: "michae" phone number: "2000000000000"
as shown keys in json have spaces, used following code in app template display json content:
<select ng-model ="sortorder"> <option selected value="{{contacts['contact name']}}">name</option> <option selected value="{{contacts['phone number']}}">contact name</option> </select> <br><br><br> <div ng-repeat="contacts in mcontactslist | orderby:sortorder"> <p>contact name: {{contacts['contact name']}}</p><br> <p>phone: {{contacts['phone number']}}</p><br> </div>
in controller, tried using:
$scope.sortorder = 'contact name'; , $scope.sortorder = '{{contacts[\'contact name\']}}';
but none worked...
the problem having sorting not working @ all, can please me pointing out doing wrong / missing? example highly appreciated
thanks
if you're going define custom orderby
-- remember takes function current repeated contact
parameter. try:
$scope.sortorder = function (contact) { return contact["contact name"]; }
Comments
Post a Comment