Home ng-repeat with ng-selected
Reply: 0

ng-repeat with ng-selected

user1432 Published in March 18, 2018, 2:11 am

I am trying to figure out how to generate list of option elements using ng-repeat, but one of them to be marked as the selected option on load.

After googling, what I found is this base, which I modified by adding the selected property to the data objects https://plnkr.co/edit/7g4MeAQnG4PzpnrebBGc?p=preview However, it seems that ng-selected="option.selected == true" has no effect :(

Why? I also have the more complex example here: http://jsfiddle.net/ej5fx3kr/14/ which works, although I am not sure what is the difference, or what is the model here used for (note: changing the model name from "program" to anything, it still works... so not sure what is the purpose).

Bonus points: How do I debug code in AngularJS in directives? Like experiment in debug mode line by line to actually see what are the variable values in that particular scope, what is available to use, etc...

My ultimate goal in this question, is to load list of values via ajax on page load in the controller, IF there is a routeParam in the URL, find it in the list of loaded values, and add selected attribute, then set selected=true in the generated HTML on page load, otherwise not pre-select anything in the populated select box on the page load, so this is why its important for me to understand this on the simplest example before trying to plug this in.


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301653 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO