2013-12-17 98 views
0

如何在app.run(function(){})中暂停执行整个应用程序?暂停执行angularjs应用程序

例如:

angular.module('frontendApp') 
    .run(function ($timeout) { 
    $timeout(function() { 
     next(); // While this function is not executed, 
       // the application must not download data and perform any task. 
    }, 1000); 
    }); 
+0

什么是你的使用情况? –

+0

我不知道该怎么做=) –

回答

1

你不能,如果你的与ng-app="frontendApp"这样引导您的应用程序。

但是,您可能可以通过手动引导进行操作。而不是在你的HTML ng-app,使用这样的事情在你的脚本:

angular.element(document).ready(function() { 
    //Bootstrap the application after 3 seconds 
    setTimeout(function() { 
     angular.bootstrap(document, ['frontendApp']); 
    }, 3000); 
}); 

也有递延引导过程中,在那里你可以拨打angular.resumeBootstrap()但我认为这是适用于测试。

此处了解详情:http://docs.angularjs.org/guide/bootstrap

+0

它不可能暂停视图加载,但加载服务? –

+0

那么这基本上延长了角度的引导过程,所以什么都不会起作用(意味着指令不会被编译,服务也不会被创建)。包含指令*的HTML页面将被加载。 – shizik