Reputation: 3530
I want to select a radio button by default. As I understand, I should add the checked attribute:
<table>
<tr>
<b> Storage </b>
</tr>
<tr>
<td>
<div class="form-group">
<input type="radio" name="store" value="local" ng-model="store" checked="checked" /> Local
</div>
</td>
<td>
<div class="form-group">
<input type="radio" name="store" value="second" ng-model="store" /> Second (Amazon)
</div>
</td>
<td>
<div class="form-group">
<input type="radio" name="store" value="cloud" ng-model="store" /> Cloud
</div>
</td>
</tr>
</table>
But Local is not checked by default (nothing is checked). Why?
Thanks in advance
Upvotes: 0
Views: 601
Reputation: 43
Use the checked attribute.
<input type="radio" name="store" value="local" ng-model="store" checked /> Local
Update
You should be using the ngChecked directive that comes with Angular.
Doc: http://docs.angularjs.org/api/ng.directive:ngChecked
Upvotes: 0
Reputation: 6092
Since you are using angular and you bind your radio buttons to your model, its state handling is done by angular based on the model.
So instead of manually trying to set the checked state of the radio, you should set the store attribute of your model to the value of the radio.
$scope.store = "local";
Upvotes: 2
Reputation: 402
Dont write checked="checked"
do this:
<input type="radio" name="store" value="local" ng-model="store" checked /> Local
Upvotes: 1