set a radio buttons to checked

663 views
Skip to first unread message

Brad Rice

unread,
Feb 28, 2014, 4:09:55 PM2/28/14
to ang...@googlegroups.com
I have a form with a bank of radio buttons that allows you to filter the results of a list. I also setup a route that pulls a param from the $routeParams that will filter the list. I want the radio button to reflect what the routeParam is, but I can't figure out how to set the radio button to checked based on that value. Can anyone push me in the right direction? I'm not sure if I use ng-checked or ng-selected and also how you go about setting those to true based on the value from inside the controller so the form controls will update.

--
Brad Rice
brad...@gmail.com
--
“Be curious. Read widely. Try new things. What people call intelligence just boils down to curiosity.”
- Aaron Swartz

Sander Elias

unread,
Mar 1, 2014, 1:11:32 AM3/1/14
to ang...@googlegroups.com
Hi Brad,

A bit hard to tell without a plunk of a fiddle. 
Radio buttons will flow around to your model, so you need to set your model depending on the variables you get from the route.

Regards
Sander

Rene Zelaya

unread,
Mar 2, 2014, 2:52:36 PM3/2/14
to ang...@googlegroups.com
Hi Brad -

I agree, having a plunk or a fiddle of your code would be useful to see what's going on.  That being said, I recommend using UI-bootstrap from angular-ui (which is a great and stable project for useful things like these - check it out here: http://angular-ui.github.io/bootstrap/).

Best,
Rene

Brad Rice

unread,
Mar 3, 2014, 4:32:35 PM3/3/14
to ang...@googlegroups.com
I wasn't sure if a plunker would work, since I am trying to make it work based on a route. Thank you Sander for the reply and that helps a lot. The thing I am wondering now with your plunker, is it possible to set one of those radio buttons when the page loads based upon a route paramater. In my case it would look like /class-search/fall.

That route id would be term=fall. I want the radio button set to the fall term.

On your plunker imaging the 3 options are summer, spring, fall. 

Sander Elias

unread,
Mar 4, 2014, 1:24:29 AM3/4/14
to ang...@googlegroups.com
Hi Brad,

So you want to so something with your route. You can as Rene told you use ui-router, but I suspect that in your case, it makes no difference for your template.
Have a look at this plunk I created a while ago. There is an button-bar in there. the button bar is automatically build from the angular router.
Also it show the active route. This is done by adding some extra data to the route's.

I think if you combine this with my previous answer you will have your solution. 

Regards
Sander Elias

Brad Rice

unread,
Mar 5, 2014, 10:06:57 AM3/5/14
to ang...@googlegroups.com
thanks Sander. You helped and I figured it out. Apparently, the issue I was having was the value was uppercased and it wasn't on the routeParam.


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/PQS_mPbv8es/unsubscribe.
To unsubscribe from this group and all its topics, 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.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages