angular.js - angular里的$setTimeout和原生的setTimeout有什么区别么?
阿神
阿神 2017-05-15 16:49:55
0
1
880

angular里的$setTimeout和原生的setTimeout有什么区别么?

阿神
阿神

闭关修行中......

reply all(1)
世界只因有你

First of all, there is no $setTimeout,是 $timeout.

Secondly, $timeout 是对 window.setTimeout is a one-layer package with basically the same functions and interfaces. The main differences are as follows:

  1. The incoming function is packaged in try...catch 结构内,并且把抛出的异常委托给 $exceptionHandler for unified scheduling processing;
  2. $timeout 返回的不是数字 ID,而是一个 promise 对象。这意味着你无法用 window.clearTimeout 取消它,而是要用 $timeout.cancel(returnedPromise) to cancel;
  3. The third parameter passed in is a Boolean value. If false is passed in, $apply will not be used to wrap the false,则不会使用 $apply 来包装 function 调用,也就是说不会更新当前作用域内的数据绑定。默认是 truefunction
  4. call, which means it will not Update data bindings within the current scope. The default is true.

Finally, these things are actually in the document...🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template