可以将 ngclick 值传递给函数吗?

Possible to pass along a ngclick value to a function?

是否有可能的解决方案来在每次点击时递增一个变量并将其传递给一个函数?我试过做这样的事情,但它不起作用。

<button ng-click="count++" ng-init="count=1" (click)="assignTasks(count)"> 

你不需要一个函数来做这个,你可以在模板上递增它。

ng-click="count = count+1"

演示版

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>

如果您仍然需要传递给函数,请使用 ng-click = "assignTasks(count)"

并在控制器函数内递增计数

您可以在同一个 ng-click 中增加和调用 assignTasks 函数,不需要 (click)="assignTasks(count)"

<button ng-init="count=1" ng-click="count = count + 1;assignTasks(count)">Click</button>

Demo