TypeScript interceptor in AngularJS -


I use typescript having trouble setting up a request interceptor in AngularJS

Following The snippet works, the working version is commented out. Anything that I do not inject into the constructor is undefined in the local variable request method.

  module service {export category AuthInterceptor {public static factory (Token Service: Services. ITokenService) {return new AuthInterceptor (Toknsrvisej); } Constructor (Private token service: Services. Information service) {this.request = (config: ng.IRequestConfig) = & gt; {Config.headers = config.headers || {}; If (this .tokenService.IsAuthorised ()) config.headers.Authorization = 'beerer' + this.TokenService.Token; Return configuration; }; } Public Request: (config: ng.IRequestConfig) = & gt; NG: Irvevest Confief; / * This public request (config) {// it is not working. TokenService is undefined here, as well as $$ or $ q, which I tried to inject config.headers = config.headers || {}; If (this. TokenService.Token! = "") Config.headers.Authorization = 'beerer' + this.TokenService.Token; Return configuration; } *}} Angular.module ("Services"). Config (($ httpProvider: ng.IHttpProvider) = & gt; {$ httpProvider.interceptors.push (Services.AuthInterceptor.Factory);});    

wrong This is due to Solution:

  public request = (config) = & gt; {// This TokenService is undetermined here, as well as $$ or $ q, which I tried to inject config.headers = config.headers || {}; If (this. TokenService.Token! = "") Config.headers.Authorization = 'beerer' + this.TokenService.Token; Return configuration; }   

To understand why you need it:

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -