问题描述
以下的jsfiddle我演示了一个问题,让我深思。它从需要茎范围的事件发送系统的所有范围,告诉他们,该系统已完成引导。
为了做到这一点,我得到引导后rootScope,并呼吁其evalAsync。唉!它不执行。
on the following jsFiddle i demonstrate a problem that makes me ponder. It stems from the need to send a system wide event to all scopes, telling them that the system has finished bootstrapping.In order to do that, i got the rootScope after bootstrapping, and called its evalAsync. Alas! its not executing.
在这里看到:
angular.element(document).ready(function() {
angular.bootstrap(body, ['app']);
var ngInjector = angular.injector(['ng']);
var rootScope = ngInjector.get('$rootScope');
var x = rootScope.$eval(function(scope) {
console.log('in eval');
scope.$broadcast('onLoad');
scope.$evalAsync(function(scope) {
console.log('in evalAsync');
scope.$broadcast('onLoad');
});
});
console.log('x',x);
console.log('after');
});
有任何想法或思想非常感谢
利奥尔
many thanks for any idea or thoughtLior
推荐答案
标记是对的调用 $消化
的功能,但有一件事:你不得到正确的根范围。
Mark is right about calling the $digest
function, but there's one more thing: you're not getting the right root scope.
angular.bootstrap
返回模块喷油器,已经拉'NG'
模块中。
angular.bootstrap
returns the injector for the modules, which already pulls in the 'ng'
module.
。
这篇关于angular.js - evalAsync不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!