Angularjs 将角度ui通知与Restanglar拦截器一起使用

Angularjs 将角度ui通知与Restanglar拦截器一起使用,angularjs,toastr,Angularjs,Toastr,我想在API在响应中返回某些代码时显示一些通知。。经过一些研究,我选择了这个模块,但我希望能够在Restanglar中的responseInterceptor中使用这些模块。 这是我当前的拦截器 RestangularProvider.setErrorInterceptor(function (response) { if (response.status !== 0) { return debouncedReportError(response); } });

我想在API在响应中返回某些代码时显示一些通知。。经过一些研究,我选择了这个模块,但我希望能够在Restanglar中的responseInterceptor中使用这些模块。 这是我当前的拦截器

RestangularProvider.setErrorInterceptor(function (response) {
    if (response.status !== 0) {
      return debouncedReportError(response);
    }
  });
  toastr.options = {
    'closeButton': true,
    'debug': true,
    'positionClass': 'toast-top-full-width',
    'onclick': null,
    'showDuration': '200',
    'hideDuration': '300',
    'timeOut': '200000',
    'extendedTimeOut': '1000',
    'showEasing': 'swing',
    'hideEasing': 'linear',
    'showMethod': 'fadeIn',
    'hideMethod': 'fadeOut'
  };

  reportError = function (response) {
    var errorOutput;

    if (response.status==403 && response.data.error.code>20000){
      Notification.success('Success notification');
      debugger;
    }
    if (typeof response.data === 'string') {
      return toastr.error('An Error occured: ' + response.statusText, 'Error: ' + response.status);
    } else if (response.data.error_message != null) {
      return toastr.error('' + response.data.error_message, 'Error: ' + response.status);
    } else if (response.data.error && response.data.error.errors != null && !_(response.data.error.errors).isEmpty()) {
      errorOutput = _(response.data.error.errors).reduce(function (memo, value, index) {
        return memo + value;
      }, '');
      return toastr.error('' + errorOutput, 'Error: ' + response.status);
    } else if (response.data.error && response.data.error.message != null) {
      return toastr.error('' + response.data.error.message, 'Error: ' + response.status);
    } else {
      return toastr.error('An error occured on the back end.', 'Error ' + response.status);
    }
  };
  return debouncedReportError = _.debounce(reportError, 2000, true);
}
我无法插入所需的服务“通知”。。非常感谢您的帮助。谢谢各位

这样,您也可以在run方法中配置restanglar,这样您就可以像下面这样配置它了

angular.module('myApp')
  .run(function(Restangular, Notification) {
    Restangular.setErrorInterceptor(
      function(response) {        
        Notification.Show()
       }
        return elem;
    });
  });
虽然示例显示了请求拦截器,但您可以用这种方式配置任何拦截器