Running $apply on $rootScope vs any other scope

前端 未结 4 2113
故里飘歌
故里飘歌 2021-01-07 16:11

The $apply function can run on any scope, including $rootScope.

Are there cases when it makes a difference if I run it on my local scope or

4条回答
  •  别那么骄傲
    2021-01-07 16:43

    Running $apply on any scope always results in a $rootscope.$digest. The only case where it might make a difference is when you provide an expression as an argument to $apply. The expression will be evaluated in the current scope (vs. $rootScope), but afterwards $rootscope.$digest is always called.

    The source code is quite clear: rootScope.js

    Bottom line: If you call $apply with no arguments, it makes no difference.

提交回复
热议问题