$routeChangeSuccess保证在新实例化的控制器中触发



假设我们有一个 /example 路由和关联的 ExampleCtrl

.when('/example', {
    templateUrl : 'example.html',
    controller: 'ExampleCtrl'
})

&

ExampleCtrl = function(){
    $scope.$on("$routeChangeSuccess", function(){
       // is this guarantied to be called inside current scope?
    }
}

大多数情况下,$routeChangeSuccess事件将在新创建的作用域内触发,但我可以依赖此假设吗?

欢迎来到 StackOverflow ;)

$scope.$on...

该位代表侦听事件$broadcast。只要你不消耗事件并故意停止传播,你就可以确定事件确实会在新的范围内触发

希望能回答你的问题

最新更新