Angular2 RC BaseRequestOption Constructor Injection

后端 未结 2 1973
闹比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:09

    This still works for me. Here is the custom option class I used:

    import {BaseRequestOptions, RequestOptions, RequestOptionsArgs} from '@angular/http';
    
    export class AppRequestOptions extends BaseRequestOptions {
      constructor() {
      }
    
      merge(options?:RequestOptionsArgs):RequestOptions {
        options.url = 'https://www.test.org' + options.url;
        return super.merge(options);
      }
    }
    

    and I register it this way:

    bootstrap(App, [
      HTTP_PROVIDERS,
      provide(RequestOptions, {useClass: AppRequestOptions})
    ]);
    

    See this plunkr: https://plnkr.co/edit/MK30JR2qK8aJIGwNqMZ5?p=preview.

    Edit

    It seems that there is a problem at the level of dependency injection for such class. I opened an issue: https://github.com/angular/angular/issues/8925.

提交回复
热议问题