Reputation: 46740
I have the following snippet in my directive template
'<li ng-repeat="f in foos">' +
'<input type="radio" ng-change="foo(f.key)" ng-model="selectedFoo" name="foos" id="{{f.key}}" value="{{f.key}}">{{f.value}}</input>' +
'</li>' +
In my link method I have
scope.foos = [
{ key: 'a', value: 'A', checked: true, symbol: 'a' },
{ key: 'b', value: 'B', symbol: 'b' },
{ key: 'c', value: 'C', symbol: 'c' }
];
scope.selectedFoo = "a";
I have method foo that does this
scope.foo = function(selectedValue) {
scope.selectedMatchType = selectedValue;
};
There are two problems that I am facing
What is wrong here?
Upvotes: 0
Views: 502
Reputation: 2201
Please note that ng-repeat creates it's own scope for every template which means you'll have to use $parent in ng-model for the input.
ng-model="$parent.selectedFoo"
Also a working fiddle with your code example: http://jsfiddle.net/hpeinar/5gj9y6k4/
Upvotes: 2