angular.js - 没有调用 evalAsync [英] angular.js - evalAsync not called

查看:21
本文介绍了angular.js - 没有调用 evalAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的 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.

见这里:http://jsfiddle.net/cusrC/8/

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 thought Lior

推荐答案

Mark 关于调用 $digest 函数是正确的,但还有一件事:您没有获得正确的根作用域.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆