0

Is that possible in some way to intercept and handle http responses being outside Angular? I can't use $httpProvider because target script is loaded after Angular has been initialized. So I need something that would work like ajaxSuccess in jQuery.

5
  • If the outside script is using jQuery you can add an interceptor for jQuery from inside Angularjs. Commented Sep 24, 2015 at 18:53
  • No, jQuery is not available here Commented Sep 24, 2015 at 19:01
  • You would need to somehow hook into angular if you want to intercept http requests sent by angular. you can't intercept http requests normally. The only reason you would be able to with jQuery sent or angular sent http requests is because each provides hooks that you can attach events to. Commented Sep 24, 2015 at 19:24
  • you would need to overload XMLHttpRequest object itself before other library loads. Keep in mind that $http will also use it too Commented Sep 24, 2015 at 19:24
  • See this overload example stackoverflow.com/questions/629671/… or stackoverflow.com/questions/16959359/… Commented Sep 24, 2015 at 19:31

1 Answer 1

1

It is rarely recommended to do that because it is un-Angular and usually indicates poor app design. But nothing stops the one from using Angular features outside of the app.

angular.module('httpModule', ['ng'], function ($httpProvider) {
  $httpProvider.interceptors.push(...);
});

var http = angular.injector(['httpModule']).get('$http');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.