I have the following constructor in my component :
constructor (private el: ElementRef) {this.el = el.nativeElement}
then in my ngOnInit
:
ngOnInit() {
let foos = this.el.getElementsByClassName('foo')
}
triggers : TS2339: Property 'getElementsByClassName' does not exist on type 'ElementRef'.
I did try converting my ElementRef
to an HTMLElement
by without any success. Any idea how to deal with that error ?
Remove private
:
el:HtmlElement;
constructor (el: ElementRef) {this.el = el.nativeElement}
With your original code this.el
will be declared as type ElementRef
but then an HTMLElement
will be assigned. This is why you get the error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With