Angular2-在加载应用程序之前获取数据
我正在寻找一种在应用程序加载时调用服务的方法 如果服务失败,我需要显示一个错误并且不加载应用程序 我看到了关于Angular2-在加载应用程序之前获取数据,angular,Angular,我正在寻找一种在应用程序加载时调用服务的方法 如果服务失败,我需要显示一个错误并且不加载应用程序 我看到了关于APP\u初始值设定项的内容,但它看起来不像我需要的 (在我的AngularJs应用程序中,我使用了run并显示了错误对话框) 请帮助这取决于您要实施的服务。例如,如果ur服务是对web api的http调用,则可以根据结果放置所需的消息: // Simple GET request example : $http.get('/someUrl'). success(function(
APP\u初始值设定项的内容,但它看起来不像我需要的
(在我的AngularJs应用程序中,我使用了run
并显示了错误对话框)
请帮助这取决于您要实施的服务。例如,如果ur服务是对web api的http调用,则可以根据结果放置所需的消息:
// 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
});