ng-repeat directive sort the data when using (key, value)

前端 未结 7 2138
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 09:40

I have a code something like this with ng-repeat = \"(key,value) in data\". In Controller:

  $scope.Dates = {\"Today\":\"30\",
                  \"This Wee         


        
7条回答
  •  不思量自难忘°
    2020-12-08 09:45

    Well, as explained in Angular's documentation for ngRepeat

    https://docs.angularjs.org/api/ng/directive/ngRepeat#iterating-over-object-properties

    when using it to iterate over the properties of an object, it will not work

    The built-in filters orderBy and filter do not work with objects, and will throw an error if used with one.

    The best solution in this case I think that is using arrays instead of an object and its properties. Therefore, just convert it to an array, iterating the properties of your object and pushing to the new array for example. After all, I think that would be the natural choice to a collection, instead of a single object with many properties.

提交回复
热议问题