mardi 24 mars 2015

Angular: How to use ngRepeat and set a default radio button option?

I checked this question, but it wasn't very helpful because they're using ng-repeat differently.


This is also not helpful.


I have a form:



<label ng-repeat="option in options">
<input type="radio" ng-model="myObject.value" ng-value="option.key">
</label>


My angular controller:



options = {
key: 'Option 1'
val: 'Value 1'
}
$scope.myObject = { value: 'default option' }


I would like this to set a default radio option. What's happening is that the last option in list is set as the default no matter what I try. I'm sure I don't understand why that is, so here I am.


How do I set a default radio option and what's wrong with my current configuration? Thanks for your help.


Aucun commentaire:

Enregistrer un commentaire