Model binding Radio buttons to a boolean.

24,207 views
Skip to first unread message

zdam

unread,
Apr 15, 2012, 10:57:41 PM4/15/12
to ang...@googlegroups.com
Hi,

I am having trouble binding a radio button to a boolean model value.

Is it possible?


Thanks, Adam.

AJ Mercer

unread,
Apr 15, 2012, 11:35:47 PM4/15/12
to ang...@googlegroups.com
works with checkboxes

        <input type="checkbox" ng-model="theBoolean">checkbox 


Not sure if this is an acceptable workaround for you - use 1 or 0
        <input name="UseBools" type="radio"  ng-model="theBoolean" value="1"  >Yes <br/>
        <input name="UseBools" type="radio"   ng-model="theBoolean" value="0">No <br/> 


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/pLP6-LVhrf8J.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.



--

AJ Mercer
<webonix:net strength="Industrial" /> | <webonix:org community="Open" />
http://twitter.com/webonix

Søren Kyndi-Wiuff

unread,
Apr 16, 2012, 7:27:13 AM4/16/12
to ang...@googlegroups.com
Hi Adam

I got this working:

In the HTML:
        <input name="UseBools" type="radio"  ng-model="getBoolean()" value="true"  >Yes <br/>
        <input name="UseBools" type="radio"   ng-model="getBoolean()" value="false">No <br/> 
In the Controller
    $scope.getBoolean function(return ""+$scope.theBoolean}; 

Cheers
Søren

Vojta Jína

unread,
Apr 20, 2012, 10:15:26 AM4/20/12
to ang...@googlegroups.com
Hey Adam, use ng-value for non string values, e.g. ng-value="true" ng-value="0" etc...

V.

--

Anil Singh

unread,
Jun 16, 2015, 1:36:54 AM6/16/15
to ang...@googlegroups.com
It might help you! go to  link http://embed.plnkr.co/XutHOu/preview

Thank you!
----------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages