Can i do this:
export class BaseComponent { protected config: IConfig; @Inject(AppConfig) protected appConfig: AppConfig; constructor() { this.config = this.appConfig.getConfig(); }
instead of this:
export class BaseComponent { config: IConfig; constructor( private appConfig: AppConfig, ) { this.config = appConfig.getConfig(); }
The goal is to simplify the signature of the constructor, so all child components do not need to specify appConfig in their constructor. So the components that inherit from BaseComponent look like this:
@Component({ selector: 'sport-templates', templateUrl: 'templates.component.html', styleUrls: [ 'templates.component.scss' ], encapsulation: ViewEncapsulation.None }) export class SportTemplates extends BaseComponent implements OnInit { constructor() { super(); }
instead of this:
@Component({ selector: 'sport-templates', templateUrl: 'templates.component.html', styleUrls: [ 'templates.component.scss' ], encapsulation: ViewEncapsulation.None }) export class SportTemplates extends BaseComponent implements OnInit { constructor(appConfig: AppConfig) { super(appConfig); }
dependency-injection angular typescript
Nikola Yankov
source share