Shane Shane - 4 months ago 9
AngularJS Question

ng-model not getting updated in radio button

Below is my code, the radio button gets checked

onload
but the
ng-model
value
session.payment
is not updated. I have to select it again to
update
.

<li ng-repeat="method in data">
<label>
<input ng-model="session.payment" ng-checked="method.active === 'ACTIVE'" type="radio" value="{{method.paymentId}}">
<span class="radio-btn"></span>
</label>
</li>

Answer

You should not use ng-checked alongside ng-model. Rather than setting the ng-checked directive onLoad, just set the session.payment variable in your controller.

So now you should have your HTML as:

<input ng-model="session.payment" type="radio" value="{{method.paymentId}}">

And in your controller:

$scope.session.payment = method.active === 'ACTIVE';