TheKingPinMirza
TheKingPinMirza

Reputation: 8952

How do i default select radio button

I have Gender radio options for repeating students. See my code below. How do i select default radio as 'Male' for each student?

<ng-repeat student in Students>
<div class="form-group col-lg-12 col-sm-8">
    <label class="col-lg-2 control-label">Gender </label>
    <div class="button-holder col-lg-2">
        <input type="radio" class="regular-radio" id="radioY_{{$index + $parent.$index}}" data-ng-model="student.Gender" data-ng-value="true" />
        <label for="radioY_{{$index + $parent.$index}}">
            <span class="Radiobox-txt" id="radioY_{{$index}}">Male</span>
        </label>
    </div>
    <div class="button-holder col-lg-2">
        <input type="radio" class="regular-radio" id="radioN_{{$index + $parent.$index}}" data-ng-model="student.Gender"  data-ng-value="false" />
        <label for="radioN_{{$index + $parent.$index}}">
            <span class="Radiobox-txt" id="radioN_{{$index + $parent.$index}}">Female</span>
        </label>
    </div>
</div>
</div>

Upvotes: 0

Views: 70

Answers (1)

Shreyas
Shreyas

Reputation: 1937

ng-value should contain the value you want to set to your model after the radio button is selected. In your case assign ng-value with 'Male' and while defining object student assign 'Male' to student.Gender

Upvotes: 1

Related Questions