angularjs - How do I call a Service from my $httpProvider -


I am struggling with all this morning, trying to call a service from my config ($ httpprovider) I have explained to many people that during config, the services are not available yet, I think that, but my service should be called from within the interceptor, which is at runtime.

I got a semi-solution that manually injected the service below, but it is not working for me, since it seems that the service is a completely new Example is being made, and I want to use the same example as the whole app (since it stores a message queue) any suggestions?

  .config (['$ httpProvider', function ($ httpProvider) {$ httpProvider.interceptors.push (function ($ q) {return {'responseError': function (reject) {/ The answer is 300 and above / errors are manually / injected from your service module, because it is not known yet. Config to var $ injector = window.angular.injector (['myServices']) var MessageService = $ Injector .get ('MessageService'); MessageService.setMessage ("We were unable to load all the required data. We are very sorry! Please try to reload this page. Or contact us if the problem is not resolved. ")}}}}}}}}]    

You can register your interceptor as a service using a factory, therefore, it should be provided with correct dependencies using the following syntax:

 {Code> .config (['$ httpProvider', function ($ httpProvider) {$. Factory ('myHttpInterceptor', ['Messaging service', function (messaging)) {retu Rn {'responseError': function (rejection) {// w Rtisad 300 and errors MessageService.setMessage ( "We were unable to load all the necessary data, we are very sorry! Please try reloading this page or contact us if the problem is not resolved.);}};}]); $ HttpProvider.interceptors.push ('myHttpInterceptor';}]);    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -