Deobfuscating Angularjs’ select directive when using key value.

Enough people want to do the select directive correctly, but still are having problems. So here is the top issue that I have tried to clear up.

So if we assume that myValueArray looks like:

    var myValueArray = [{id:1, name:"bob"},{id:2, name:"bill"},];

and we assume that myVar looks like

    var myVar = 2;

And here is the HTML

    <select ng-model="myVar" required ng-options="obj.id as obj.name for obj in myValueArray">
    </select>

Then you will get a drop-down that is prepopulated with bob and bill, but bill is selected.

Advertisements
This entry was posted in Brian's Code Extreme, JavaScript and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s