2016-10-10 |

如何取消 $timeout , 以及停止一个 $watch() ?

A
B
C
D
答案:
解释:

停止 $timeout我们可以用cancel

var customTimeout = $timeout(function () {  
  // your code
}, 1000);

$timeout.cancel(customTimeout);

停掉一个 $watch

// .$watch() 会返回一个停止注册的函数
function that we store to a variable  
var deregisterWatchFn = $rootScope.$watch(‘someGloballyAvailableProperty’, function (newVal) {  
  if (newVal) {
    // we invoke that deregistration function, to disable the watch
    deregisterWatchFn();
    ...
  }
});
html5面试题
it面试经验

发表评论

    评价:
    验证码: 点击我更换图片
    最新评论