2013-12-17 99 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