Angular2 RC BaseRequestOption Constructor Injection

后端 未结 2 1971
闹比i
闹比i 2021-01-21 20:52

I don’t know whether I am missing something but injecting the constructor of a custom baserequestoptions class was working fine for me in Beta 17 but after moving to RC1 this ap

2条回答
  •  情书的邮戳
    2021-01-21 21:25

    Extending from RequestOptions instead of from BaseRequestOptions made it work for me

    @Injectable()
    export class AppRequestOptions extends RequestOptions {
      constructor(@Inject('webApiBaseUrl') private webApiBaseUrl:string) {
        super({method: RequestMethod.Get, headers: new Headers()});
        console.log('webApiBaseUrl', webApiBaseUrl);
      }
    
      merge(options?:RequestOptionsArgs):RequestOptions {
        options.url = this.webApiBaseUrl + options.url;
        console.log('merge - options.url = '+options.url);
        return super.merge(options);
      }
    }
    

    otherwise for some unknown reason injecting @Inject('webApiBaseUrl') private webApiBaseUrl:string didn't work.

    Plunker example

提交回复
热议问题