Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2-在加载应用程序之前获取数据_Angular - Fatal编程技术网

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
  });