Monday, April 13, 2015

AngularJS radio button not working in ng-repeat repeater

In AngularJS the ng-repeat element will create it's own scope. This means that if you try and access an ng-model on a radio button element in an ng-repeat repeater, the value would come back undefined. This can be fixed by simply setting the ng-model of the radio button to be prefaced with "$parent.", this then sets the model in the parent (aka where your main controller is).
<input type="radio" name="MyRadio" ng-model="$parent.MyModel" value="{{i.Value}}" /> 

No comments:

Post a Comment