<ul>
<li ng-repeat="val in [1,2,3]">
<button ng-click="dummy = '{{val}}'">{{val}}</button>
</li>
</ul>
<div>Value : {{dummy}}</div>
I am trying to assign a value when the button is clicked but its not working.
<ul>
<li ng-repeat="val in [1,2,3]">
<button ng-click="dummy = '{{val}}'">{{val}}</button>
</li>
</ul>
<div>Value : {{dummy}}</div>
I am trying to assign a value when the button is clicked but its not working.
ng-repeat
creates its own scope. Since the button is in the ng-repeat
, it has an individual scope, and can't access the dummy
value. To prevent this, your need to use a dot in your ng-model.
Here is your code, corrected: http://jsfiddle.net/844k52bh/
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.changeDummyVal=function(val){
$scope.dummy=val;
}
});
You can make function for it
You just need to do:
ng-click="dummy = val "
i.e
<ul>
<li ng-repeat="val in [1,2,3]">
<button ng-click="dummy = val ">{{val}}</button>
</li>
</ul>
<div>Value : {{dummy}}</div>