问题
i have the following class which i want to extend.
export class AngularComponent {
constructor(
private r: Renderer2,
private editorService: AngularEditorService,
@Inject(DOCUMENT) private doc: any,
private sanitizer: DomSanitizer,
private cdRef: ChangeDetectorRef,
@Attribute("tabindex") defaultTabIndex: string,
@Attribute("autofocus") private autoFocus: any
)
}
So i create the following class:
export class EnhancedComponent extends AngularComponent{
constructor(private r: Renderer2, private editorService: AngularEditorService){
super(r,editorService, ...)
}
}
However i don't know how to pass the other dependencies
@Inject(DOCUMENT) private doc: any,
@Attribute("tabindex") defaultTabIndex: string,
@Attribute("autofocus") private autoFocus: any
Thanks for your help
回答1:
This should probably do the trick:
https://devblogs.microsoft.com/premier-developer/angular-how-to-simplify-components-with-typescript-inheritance/
Basically you use the Injector
class to retrieve your injections instead of constructor injection.
来源:https://stackoverflow.com/questions/59659868/angular-2-how-to-extend-class-which-has-dependency-injections