I'm building a dynamic list of radio inputs based on JSON data coming from an API.
I'm using ngRepeat
+ track by
, input[radio]
and ngValue
.
Any new XHR request will refresh the data in the scope but the currently checked radio (if any) will be unchecked.
See this plnkr demo: http://embed.plnkr.co/2q1A7krBzxIjkfwhXYcK/preview
This can be solved by using the interpolation directive in ngValue
, but it feels like I'm doing it wrong:
<input type="radio" name="c" ng-value="{{ choice }}" ng-model="selected.choice" required>
This can also be solved by using ng-init
but it still feels like I'm doing it wrong:
<input type="radio" name="c" ng-init="c = choice" ng-value="c" ng-model="selected.choice" required>
Can somebody please explain me what's going on?
Related questions: