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=" as for obj in myValueArray">

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

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.