Wednesday, January 14, 2015

Angular.js ng-options – bind to key instead of object

In an Angular.js application we are building I had the following situation:

I have an array of option objects containing a label and a value that is used as input for a select list. On my controller I want to bind to the selected value (and not to the selected object!).

Here is the controller:

First I had the following code in  the view:

The above code resulted in the selectedValue set to the complete option object and not to the option.value property.

To fix it, I had to update the view code to the following:

No comments: