I have a problem dynamically generating options for a radio model in angular's ui.bootstrap. I thought I could simply ng-repeat over an array, using it's contents for the btn-radio attribute like so:
//in the controller
$scope.radioModel = undefined;
$scope.radioModelButtons = ["a", "b", "c"];
//in the html
<div class="btn-group" >
<button ng-repeat="value in radioModelButtons"
class="btn" type="button" ng-model="radioModel"
btn-radio="'{{value}}'">
{{value}}
</button>
</div>
I'm using angular 1.1.4 and ui.bootstrap 0.3.0.
Here is a jsfiddle of my efforts, as you can see, the radio buttons act independently and do not affect the radioModel variable.
Thanks!
This is how you should write your markup:
<button ng-repeat="value in radioModelButtons"
class="btn" type="button" ng-model="radio.model"
btn-radio="value">
{{value}}
</button>
And the working jsFiddle: http://jsfiddle.net/yMLqz/2/
There were 2 problems in your approach:
btn-radio
should be used with AngularJS expression, and not an interpolated valueng-repeat
is creating a new scope so you need to take this into account if you want to bind to a value defined on a parent scopeIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With