AngularJS ng-click toggling between functions

一个人想着一个人 提交于 2019-12-25 03:19:16

问题


<span ng-click="resetbyTask() || filterTask(task.id, $index)">{{ task.total }}</span>

I am trying to toggle between fucntions in a single ng-click so that the first click will run filterTask() and when clicked again it will run resetbyTask


回答1:


Try this :

// controller

var called = false;

$scope.toggle = function (taskId, index) {
  if (called) { called = false; return $scope.resetbyTask(); }
  $scope.filterTask(taskId, index);
  called = true;
}

HTML :

<span ng-click="toggle(task.id, $index)">{{ task.total }}</span>


来源:https://stackoverflow.com/questions/25936286/angularjs-ng-click-toggling-between-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!