Change a value inside ng-repeat cycle with ng-click
When using controllerAs
pattern, you should be using controller
alias while accessing any variable from controller function. But that should be bounded to this
context of controller
.
<button ng-click="todoList.example(todo)">Click me</button>
Extended
Also keep in mind while using this
keyword inside a controller factory function. You should assign this
variable to some variable to ensure that this
which you are using is not other this
, look at this
context related issue.
angular.module('todoApp', []) .controller('TodoListController', function() { var toList = this; toList.todos = [{name:'test 1'},{name:'test 2'}]; toList.example = function(v) { v.name = 'ora bene'; }; });