Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate with ng-options in a dictionary(object) [closed]

I need to iterate over the following object with ng-options:

var a = {
'optionName1': 'optionValue1',
'optionName2': 'optionValue2',
'optionName3': 'optionValue3',
'optionName4': 'optionValue4',
};

I get this object in this format from a 3rd party resource, and I'd rather no to re-arrange it manually.

I already did a Google search, and looked into the documentation, it deals with lists, and lists of objects only from what I could tell.

like image 589
Oleg Belousov Avatar asked Sep 18 '13 10:09

Oleg Belousov


1 Answers

For a model like this:

$scope.options = {
    'optionName1': 'optionValue1',
    'optionName2': 'optionValue2',
    'optionName3': 'optionValue3',
    'optionName4': 'optionValue4',
};

You can create options like this:

<select ng-change="change()" ng-model="votes.status" 
ng-options="v for (k,v) in options">
</select>
like image 176
AlwaysALearner Avatar answered Oct 22 '22 06:10

AlwaysALearner