Ced*_*Ced 2 javascript web angularjs typescript
我正在开发一个角度应用程序,我正在使用一个服务,它应该在继续执行应用程序之前从服务器加载一些细节.
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 Code Online (Sandbox Code Playgroud)
这样的事情甚至可能吗?
不在.run- 该.run功能不会"阻止".通常,人们可以使用ngRoute/ ui-router并使用该resolve属性.
如果你不想走这条路,你可以创建一个应用级控制器并在那里"解决":
.controller("AppCtrl", function($scope, loaderSvc){
$scope.load = false;
loaderSvc.preload().then(function(){
$scope.load = true;
});
});
Run Code Online (Sandbox Code Playgroud)
并在视图中:
<div ng-controller="AppCtrl">
<div ng-if="::load" ng-include="'main.html'">
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5860 次 |
| 最近记录: |