ivanesi
ivanesi

Reputation: 1663

Angular model for input

<input type="checkbox" ng-model="master" ng-checked="false" name="one"><br/>
<input type="checkbox" ng-disabled="master" name="two">  

It works. But if i replace "checkbox" to "radio" it doesn't work. I tired to try make one radio disabled when other checked.

Why it doesn't work? How to do this?

thanks.

Upvotes: 0

Views: 89

Answers (2)

user1938667
user1938667

Reputation:

For me this works fine.

HTML

<input class="radio2" type="radio" id="r1" name="group1"
       ng-model="radioValue"
       ng-value="1">
<input class="radio2" type="radio" id="r2" name="group1"
       ng-model="radioValue"
       ng-value="2">

Inside Your Controller

$scope.radioValue = -1; /* Select none. */
$scope.radioValue = 0; /* Select none. */
$scope.radioValue = 3; /* Select none. */
$scope.radioValue = 1; /* Select r1. */
$scope.radioValue = 2; /* Select r2. */

var selected = $scope.radioValue; /* get selected value. */

Upvotes: 0

Dalorzo
Dalorzo

Reputation: 20024

Radio button use ng-value instead... Radio button work based on value to mark a value as selected. You need either [value="" | ng-value=""]

<input type="radio"
       ng-model=""
       [value="" |
       ng-value=""]>

Like:

 <input type="radio" ng-value="true" name="boolean" ng-model="myValue" /> True
 <input type="radio" ng-value="false" name="boolean"  ng-model="myValue" /> False 

Here is a Online Demo

Or with strings values like:

$scope.myValue = 'Car'

html

 <input type="radio" ng-value="'Car'" name="string1" ng-model="myValue" /> Car
 <input type="radio" ng-value="'Airplane'" name="string1"  ng-model="myValue" /> Airplane 

Here is the second Online Demo

Upvotes: 2

Related Questions