如何报告来自AngularJS$q.all的错误?

如何报告来自AngularJS$q.all的错误?,angularjs,Angularjs,我的代码如下所示: $q.all([ this.getData(EnumGetData.ContentStatus), this.getData(EnumGetData.ContentType), this.getData(EnumGetData.UserProfile), ]) .then((results) => { self.contentStatus = results[1];

我的代码如下所示:

    $q.all([
        this.getData(EnumGetData.ContentStatus),
        this.getData(EnumGetData.ContentType),
        this.getData(EnumGetData.UserProfile),
    ])
        .then((results) => {
            self.contentStatus = results[1];
            self.contentType = results[2];
            self.userProfile = results[3];
        }, function () {
            alert // 
        });
        getData(controller) {
我的getData函数参数如下所示:

    $q.all([
        this.getData(EnumGetData.ContentStatus),
        this.getData(EnumGetData.ContentType),
        this.getData(EnumGetData.UserProfile),
    ])
        .then((results) => {
            self.contentStatus = results[1];
            self.contentType = results[2];
            self.userProfile = results[3];
        }, function () {
            alert // 
        });
        getData(controller) {
如果出现错误,My getData函数将返回以下内容:

        .error((data, status, headers, config) {
            defer.reject();
        });

如果$q.all失败,我想做的是发出一条警告消息。谁能建议我怎么做

这里有一个plunker,显示您需要做什么

您可以像这样传递错误消息:deferred.reject('error message'),然后您可以在then的错误处理程序中捕获它

function getData(input) {
    var deferred = $q.defer();

    $timeout(function() {
      deferred.reject(input);
    }, 2000);

    return deferred.promise;
  }

  $q.all([getData(1),
    getData(2),
    getData(3)
  ]).then(function success(data) {
    console.log('should not get here');
  }, function(error) {
    alert(error);
  });