admin管理员组文章数量:1244304
I'm working on an angular application and I'm using a service which should load some details from the server before the execution of the application is continued.
application.run(($myService)=>{
myService.loadSomething() //The application should pause until the execution of the Service
//is pleted until this the browser shoudl stay in a "loading state"
});
Is sometehing like this even possible?
I'm working on an angular application and I'm using a service which should load some details from the server before the execution of the application is continued.
application.run(($myService)=>{
myService.loadSomething() //The application should pause until the execution of the Service
//is pleted until this the browser shoudl stay in a "loading state"
});
Is sometehing like this even possible?
Share Improve this question asked Apr 9, 2015 at 6:27 CedCed 1,30111 silver badges31 bronze badges3 Answers
Reset to default 8Not in the .run
- the .run
function will not "block". Typically, one can use ngRoute
/ui-router
and use the resolve
property.
If you don't want to go this route, you could create an app-level controller and "resolve" there:
.controller("AppCtrl", function($scope, loaderSvc){
$scope.load = false;
loaderSvc.preload().then(function(){
$scope.load = true;
});
});
and in the View:
<div ng-controller="AppCtrl">
<div ng-if="::load" ng-include="'main.html'">
</div>
Get yourself familiar with $q and try to plan your application as it must not wait for anything to happen. Asynchronism is the key of every AngularJS app.
If you are using the router, get familiar with resolve
, that may also help you "waiting" for data before a route/view will be shown.
I had a similar requirement and I ended up using angular-deferred-bootstrap by @philippd.
For a detailed question and thought provoking discussion plz check AngularJS : Initialize service with asynchronous data
本文标签: javascriptAngular wait for promise in modulerunStack Overflow
版权声明:本文标题:javascript - Angular wait for promise in module.run - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740110989a2226207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论