-1
如果服務將失敗,我需要顯示錯誤並且不加載應用程序,我正在尋找一種方法來調用應用程序加載服務 。Angular2 - 在應用程序加載前獲取數據
我看到了有關APP_INITIALIZER
,但它並不像我所需要的 (我AngularJs軟件,我用run
和錯誤顯示的對話框) 請幫助
如果服務將失敗,我需要顯示錯誤並且不加載應用程序,我正在尋找一種方法來調用應用程序加載服務 。Angular2 - 在應用程序加載前獲取數據
我看到了有關APP_INITIALIZER
,但它並不像我所需要的 (我AngularJs軟件,我用run
和錯誤顯示的對話框) 請幫助
這取決於ü要實現服務的。如果例如你的服務是一個http調用web api,你可以根據結果放上你想要的信息:
// Simple GET request example :
$http.get('/someUrl').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
// put ur message error here and redirect to onother route if u want
});