AngularJS ng-click toggling between functions

2019-08-29 00:31发布

<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条回答
迷人小祖宗
2楼-- · 2019-08-29 01:15

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>
查看更多
登录 后发表回答