gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 16:18:17 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com