1
votes

I'm new with AngularJS, found this binding to radio button in documentation (http://docs.angularjs.org/api/ng.directive:ngValue) and then tried to change it to button but then it doesn't work anymore ?!

It is a very simple selector, when you select radio button it displays what you've selected, but when you click the same button it doesn't do anything.

VIEW:

<input type="radio" ng-model="selected.0" ng-value="item" ng-repeat="item in items" for="{{item}}">{{ item }}

<input type="button" ng-model="selected.0" ng-value="item" ng-repeat="item in items" for="{{item}}" >

<br>selected: {{selected.0}}

CONTROLLER:

$scope.items = ['settings', 'home', 'other'];
$scope.selected = [''];
2
You need to use ng-click for the button - tymeJV
Thank you all for your help, saved me a lot of time :) - marebine

2 Answers

0
votes

For the button input, you can just get rid of the ng-model and using ng-click to set the item value simply like:

ng-click = "selected.0=item"

Working example in jsFiddle

0
votes

I tried to implement the functionality you asked by moving ng-repeat directives to outer elements. I also used ng-click directives on buttons. Here's a working example.