Default select values inside ng-repeat

5,043 views
Skip to first unread message

Rob Stinogle

unread,
Feb 3, 2013, 12:34:15 PM2/3/13
to ang...@googlegroups.com
Hey guys,

I've got two select elements in my controller file, and I'm iterating through them with ng-repeat. I'm trying to set all the values to a default, which doesn't seem to be working. I've got the below fiddle as close as I can get... it's currently setting the default for one of the two in the array. I tried attaching an $index counter to the ng-model, but that didn't seem to work. What am I missing?


Thanks!
_Rob

Peter Bacon Darwin

unread,
Feb 3, 2013, 4:01:58 PM2/3/13
to ang...@googlegroups.com
Not really sure what you are getting at here but how about this?


_Rob

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Rob Stinogle

unread,
Feb 3, 2013, 11:58:47 PM2/3/13
to ang...@googlegroups.com
Ahhhh ok, I see now. Seems like ng-init was the golden ticket I was looking for! Basically, I want to be able to loop through multiple data objects, draw out a select for each, and then default them each to a variable I set. Here is a much cleaner fiddle Peter, with me setting each to the first element in the array. I assume I can set a variable in my data, and replace the hard coded integer and I should be good to go!


That look right to you Peter?

Thanks so much for the reply! Starting to finally get this Angular stuff, even if just a minuscule amount :)
_Rob

Peter Bacon Darwin

unread,
Feb 4, 2013, 4:15:18 AM2/4/13
to ang...@googlegroups.com

As long as the values are not already set. You may want to check...

Ng-init ="option = option || defaultValue "

Pete
...from my mobile.

Reply all
Reply to author
Forward
0 new messages