Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use notification in HttpInterceptor #29

Closed
lenczykt opened this issue Jun 22, 2015 · 2 comments
Closed

Use notification in HttpInterceptor #29

lenczykt opened this issue Jun 22, 2015 · 2 comments

Comments

@lenczykt
Copy link

Hi,

I'd like to use Notification in my interceptor. It's seams that i can't because there is circular dependency problem:

$http <- Notification <- errorHttpInterceptor <- $http <- $templateRequest <- $compile

This is how i'm registering interceptor:

angular.module('myModule', [])
  .config(function($httpProvider) {
    $httpProvider.interceptors.push('errorHttpInterceptor');
  });

angular
  .module('myModule')
  .factory('errorHttpInterceptor', function (Notification) {

    return {
      'responseError': handleErrorResponse
    };

    function handleErrorResponse(response) {
        Notification.error('error');
    }

Do you have any ideas?

@alexcrack
Copy link
Owner

Yes. I have an idea. Try to use $injector manually.
Example:

angular.module('myModule', [])
  .config(function($httpProvider) {
    $httpProvider.interceptors.push('errorHttpInterceptor');
  });

angular
  .module('myModule')
  .factory('errorHttpInterceptor', function ($injector) {

    var Notification = $injector.get('Notification');

    return {
      'responseError': handleErrorResponse
    };

    function handleErrorResponse(response) {
        Notification.error('error');
    }

@lenczykt
Copy link
Author

Thank you. It works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants