angular.js - evalAsync不叫 [英] angular.js - evalAsync not called

查看:169
本文介绍了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 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天全站免登陆