当我按下此按钮时,如何在按钮上执行$watch()
并触发$watch()
?
HTML:
<button style="margin-left:10px;" class="btn btn-danger btn-xs">
Re-init tableau
</button>
JS:
scope.$watch('[]', function () {}, true);
答案 0 :(得分:2)
您可以在按钮上添加ngClick
:
<button ng-click="addWatch()" style="margin-left:10px;" class="btn btn-danger btn-xs">
Re-init tableau
</button>
并在您的控制器中:
$scope.addWatch = function(){
if( !$scope.isWatchAdded ) {
$scope.$watch('[]', function () {}, true);
$scope.isWatchAdded = true;
}
}
这将只添加一次watch
表达式