0

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

AngularChan
  • 135
  • 2
  • 11

1 Answers1

0

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.

puGoNaut
  • 135
  • 4
  • Thx, but how can i do it in my case. In my case i can't modify the base class. It comes from a library ... – AngularChan Jan 09 '20 at 08:43
  • If you can't modify the base class, you probably need to wrap it into your own BaseComponent which instantiates the lib component. – puGoNaut Jan 09 '20 at 08:47