Inherit Dependency injection

前端 未结 2 1048
面向向阳花
面向向阳花 2021-01-21 20:31

I want to create a generic api service in order to make model-related services easier to create:

export abstract class ModelService {

    constructor(p         


        
2条回答
  •  无人共我
    2021-01-21 21:00

    The constructor needs to repeat the dependencies and then passed to the super class using super(...)

    @Injectabe()
    export class FooService extends ModelService{
        constructor(apiService: ApiService) {
          super(apiService);
            //ApiService is a service that wraps Http and adds signature , auth and serialization.
        }
    }
    

    This is not an Angular2 requirement or limitation, that's how constructors work in TypeScript.

提交回复
热议问题