user3726986
user3726986

Reputation:

Angular Js Default Radio Button Selection

I am using the following piece of code for selecting the first option for radio button, but somehow it doesn't seem to work

<label class="radio inline">
    <input type="radio" ng-value="true" name="smsEnabled" ng-model="contactNumberArray.smsEnabled1" ng-checked="true">Yes
</label>
<label class="radio inline">
    <input type="radio" ng-value="false" name="smsEnabled" ng-model="contactNumberArray.smsEnabled1">No
</label>

Can someone suggest some work around for this ?

Upvotes: 0

Views: 1732

Answers (1)

sylwester
sylwester

Reputation: 16508

Hi in your controller you have to set default value for contactNumberArray please see here: http://jsbin.com/dafoj/1/edit

JS:

  $scope.contactNumberArray ={

    smsEnabled1 : true
  };

HTML:

 <label class="radio inline">
    <input type="radio" ng-value="true" name="smsEnabled" ng-model="contactNumberArray.smsEnabled1" ng-checked="true">Yes
</label>
<label class="radio inline">
    <input type="radio" ng-value="false" name="smsEnabled" ng-model="contactNumberArray.smsEnabled1">No
</label>

Upvotes: 1

Related Questions