0

I was doing the mockup page with using angular JS and html only. I wonder if there is faster that can dynamic bind the selected value in HTML to the angular object Such as if I have sth like:

      item.dropdownvalue = 0;

      <select>
             <option value=0>Pre-Launch</option>
             <option value=1>Active</option>
             <option value=2>Complete</option>
       </select> 

That I can bind it to the dropwown so it turn to be:

       <select>
             <option value=0 selected>Pre-Launch</option>
             <option value=1>Active</option>
             <option value=2>Complete</option>
       </select> 

Just like the HTML Dropdown Helper in MVC5

1

1 Answer 1

1

SIMPLIFIED:

If you're just wanting to affect the selected state, you can do your own HTML and just bind a scope value to the selected option via ng-model. See simplified Plunker at http://plnkr.co/edit/YIwBhEQOKDFgjKmv9Qvy?p=preview

ORIGINAL ANSWER:

This can be accomplished by having an array with your values and building the select with the ng-options Angular directive:

<select name="state" ng-model="dropdownvalue" ng-options="states.indexOf(state) as state for state in states"></select>

You can see this in action in the following Plunker: http://plnkr.co/edit/HY9Zpzbe9MhrYCVdNtgi?p=preview

Sign up to request clarification or add additional context in comments.

2 Comments

Hum I am looking for a more simple solution that I can do it without create the state, but thanks of your work
Did a simplified version that doesn't build the options in Angular and only relies on the data binding to create the selected option. Is this what you're looking for? If this helps, please upvote and award the answer. Best of luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.