MIDE11
MIDE11

Reputation: 3530

HTML / Select radio button doesn't work

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

Answers (3)

Jorge
Jorge

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

David Frank
David Frank

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

FKutsche
FKutsche

Reputation: 402

Dont write checked="checked" do this:

<input type="radio" name="store" value="local" ng-model="store" checked /> Local

Upvotes: 1

Related Questions