Angular 2 inject service into extended class(BaseRequestOptions)

后端 未结 2 914
野性不改
野性不改 2021-01-27 04:04

I have the following code that extends the BaseRequestOptions class:

import { Injectable } from \'@angular/core\';

@Injectable()
export class AppReq         


        
2条回答
  •  余生分开走
    2021-01-27 04:28

    This is very similar to the question I answered here: Injected dependency is undefined when extending BaseRequestOptions

    When defining your provider also define the dependencies needed, so the object in your providers definition would look like:

    {
     provide: RequestOptions,
     useClass: AppRequestOptions,
     deps: [ServiceA]
    }
    

提交回复
热议问题