I am writing an Angular package where I will provide basic functionalities and allow user to extend it for customization according to their needs. Base component includes some services which I will use internally. So when I extend this component in my application it gives error because it needs super() call with the internally used services as parameters.
I checked this issue(https://github.com/angular/angular/issues/5155) on Angular GitHub repo which suggests to use 'Injector' to inject services in base component but that does not seem a correct way to do. Is there any better structure for this situation.
Base Component
Component({
selector: 'base-comp',
template: `
<p>
base-comp works
</p>
`,
styles: []
})
export class BaseComp implements OnInit {
constructor(private someservice: SomeService,
private anotherService: AnotherService
) {
}
}
Child Component
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent extends BaseComp {
constructor(private localService: LocalService) {
super(); // this gives error
}
}
I want child component to inherit without passing all the dependencies in super() call in constructor.