AngularJS orderBy property incorrect

38 Views Asked by At

I'm iterating over an array of objects and would like them sorted alphabetically by the 'ecuName' property. I don't understand why 'HVAC' is rendering before 'ABC'.

    "ecuInfoList": [
      {
        "id": 4,
        "ecuName": "ACC"
      },
      {
        "id": 6,
        "ecuName": "HVAC"
      },
      {
        "id": 5,
        "ecuName": "ABG"
      }
    ]

Edit

Forgot to add the template code.

<div ng-repeat="ecu in config.ecuInfoList | orderBy:'ecuName' track by $index"><strong>{{ ecu.ecuName }}</strong>...

enter image description here

1

There are 1 best solutions below

0
On

You might now access the array with ng-repeat properly. Check the working DEMO

DEMO

var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
 $scope.data = { "ecuInfoList": [
      {
        "id": 4,
        "ecuName": "ACC"
      },
      {
        "id": 6,
        "ecuName": "HVAC"
      },
      {
        "id": 5,
        "ecuName": "ABG"
      }
    ]
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
 <div ng-repeat="mydata in data.ecuInfoList | orderBy:'ecuName'">
   {{mydata.ecuName}}
 </div>
</body>