Model binding Radio buttons to a boolean.

已查看 24,231 次
跳至第一个未读帖子

zdam

未读,
2012年4月15日 22:57:412012/4/15
收件人 ang...@googlegroups.com
Hi,

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

Is it possible?


Thanks, Adam.

AJ Mercer

未读,
2012年4月15日 23:35:472012/4/15
收件人 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

未读,
2012年4月16日 07:27:132012/4/16
收件人 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

未读,
2012年4月20日 10:15:262012/4/20
收件人 ang...@googlegroups.com
Hey Adam, use ng-value for non string values, e.g. ng-value="true" ng-value="0" etc...

V.

--

Anil Singh

未读,
2015年6月16日 01:36:542015/6/16
收件人 ang...@googlegroups.com
It might help you! go to  link http://embed.plnkr.co/XutHOu/preview

Thank you!
----------------------------------------------------------------------------------
回复全部
回复作者
转发
0 个新帖子