I have been trying to figure out how to use an array if objects as the key values for an ng-select directive
this is the data I want to use
$scope.selectValues [
{name: "Options 1", value: "11"},
{name: "Options 2", value: "22"}
{name: "Options 3", value: "33"}
];
and I want the output to be
<select>
<option value="11">Options 1</option>
<option value="22">Options 2</option>
<option value="33">Options 3</option>
</select>
Can anyone explain how to do this ? and show a an example of the directive set up? I have looked at the docs but they don't have an example that fits for the this model.
ng-options
supports both array and object based data source. For example:Array based data source:
Object based data source:
However, you are using an incompatible data structure for the array based option. You can use like this:
and use the selected value as
selected.value
. (selected
is bound to one of the objects in the array). This won't work if you want to submit the form via HTTP, so in this case you should convert the options to one of the data structure mentioned above.I've included these three usage here: http://plnkr.co/IEBQkqJNifY5MZWloDP6
Edit: So I looked at the docs again today and found the way to work with your original data structure.
The plnkr is updated also.