我正在开发一个 Angular 应用程序,我正在使用一项服务,该服务应在继续执行应用程序之前从服务器加载一些详细信息。
application.run(($myService)=>{
myService.loadSomething() //The application should pause until the execution of the Service
//is completed until this the browser shoudl stay in a "loading state"
});
这样的事情有可能吗?
最佳答案
不在 .run
中 - .run
函数不会“阻塞”。通常,可以使用 ngRoute
/ui-router
并使用 resolve
属性。
如果你不想走这条路,你可以创建一个应用级 Controller 并在那里“解决”:
.controller("AppCtrl", function($scope, loaderSvc){
$scope.load = false;
loaderSvc.preload().then(function(){
$scope.load = true;
});
});
在 View 中:
<div ng-controller="AppCtrl">
<div ng-if="::load" ng-include="'main.html'">
</div>
关于javascript - Angular 等待 module.run 中的 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29531298/