Running $apply on $rootScope vs any other scope

前端 未结 4 2148
故里飘歌
故里飘歌 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 17:04

    Another reason for running $apply on the $rootScope instead of $scope typically comes for me when I need to call $apply in a service which will be used by different controllers and therefore different scopes.
    In this cases I prefer to inject the $rootScope to the service and call $apply on it without worrying on which scopes the service will be used in the future.

提交回复
热议问题