当我多次点击我的按钮时如何触发手表

时间:2014-12-30 14:59:51

标签: javascript angularjs

当我多次按下此按钮时,如何在按钮上执行$ watch()并触发my watch()?

HTML:

<button ng-click="addWatch()" style="margin-left:10px;" class="btn btn-danger btn-xs">
                    Re-init tableau
</button>


....

<mtx-matrice-form matrix="matrix " isclicked="isWatchAdded "></mtx-matrice-form>

js控制器:

$scope.addWatch = function(){
    if( !$scope.isWatchAdded ) {
      $scope.isWatchAdded = true;
    }
}

指令:

angular.module('matrixarMatrice', []).directive('mtxMatriceForm', function () {
    return {
        restrict: 'E',
        templateUrl: 'views/matrice/matrice.html',
        scope: {
            matrix: '=',
            isWatchAdded : '='
        },
        link: function (scope, element, attrs) {
...
          $scope.$watch('isWatchAdded ', function () {}, true);    

...

它按时运行我希望在点击我的按钮时运行

0 个答案:

没有答案