Reputation: 147
Is there a possible solution to increment a variable on each click and pass along to a function? I tried doing something like this but it doesn't work.
<button ng-click="count++" ng-init="count=1" (click)="assignTasks(count)">
Upvotes: 3
Views: 69
Reputation: 4448
You can both increment and call assignTasks function inside the same ng-click, there is no need for (click)="assignTasks(count)"
<button ng-init="count=1" ng-click="count = count + 1;assignTasks(count)">Click</button>
Upvotes: 2
Reputation: 222582
You do not need a function to do this, you can just increment it on the template.
ng-click="count = count+1"
DEMO
var app = angular.module('test',[]);
app.controller('testCtrl',function($scope){
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="test" ng-controller="testCtrl">
<button ng-init="count=1" ng-click="count = count+1"> Pass {{count}} </button>
</body>
If you still need to pass to a function use ng-click = "assignTasks(count)"
and increment count inside the function of controller
Upvotes: 2