How to sort array in ng-options by key?

[亡魂溺海] 提交于 2019-12-03 13:12:10

In order to use tracking with filters use track by.

Markup

ng-options="key as value for (key, value) in data.month | orderBy:'key' track by key"

Update

This orderBy will never work because you are having literal array. You need to convert this array to JSON like object which would structured like [{id: 0, value: "M"}, {id: 1, value: "January"},......]

HTML

ng-options="item.id as item.value for items in data.month | orderBy:'id'"

Demo Plunkr

Your missing two ''s. This part, orderBy: key should be orderBy:'key'

Try this:

ng-options="key as value for (key, value) in data.month | orderBy: 'key'"

To resolve this issue need reformat ng-option like as:

day.id as day.value for day in data.month

And array data.month would be how as told user pankajparkar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!