javascript - 如何在 angular.bootstrap() 之后设置 $rootScope 的值

标签 javascript angularjs

我正在使用 angular.bootstrap() 来初始化我的应用程序。在此之后,我想为我的 $rootScope 分配一些值。我正在尝试这个,但它对我不起作用:

var app = angular.module('myApp', []);
var modulesToLoad = ['myApp'];
angular.bootstrap(b, modulesToLoad);
app.run(function($rootScope) {
    $rootScope.isLoading = false;
}

最佳答案

bootstrap 函数返回 $injector,所以你可以这样做:

var app = angular.module('myApp', []);
var modulesToLoad = ['myApp'];
var injector = angular.bootstrap(b, modulesToLoad);
injector.invoke(function($rootScope) {
    $rootScope.isLoading = false;
});

关于javascript - 如何在 angular.bootstrap() 之后设置 $rootScope 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13198443/

相关文章:

javascript - 如何使用表单数据打印值?

javascript - Angular 用户界面 TinyMCE : How set default settings

javascript - 如何排除某些文件在 Typescript 中被编译?

javascript - Rails PATCH 方法而不是 POST

javascript - 如何更改 SVG 路径颜色?

javascript - 错误 : [$compile:multidir] for Component Directive with Attribute Directive

javascript - Flutter Webview 与 Javascript 的双向通信

模板文字字符串问题中的 Javascript 函数参数

angularjs - UI-Grid 分页模板可编辑

http - Angular ——访问多个 http 调用的数据——如何解决 promise