I want to get a HTML element with DOM manipulation. When I try to get the element with ViewChild, it gives the following error. When I click the quick fix, it adds | undefined. But this time I can not call the variable as this.map
Property 'map' has no initializer and is not definitely assigned in the constructor.
import { Component, ElementRef, OnInit, ViewChild, AfterViewInit } from '@angular/core';
export class SlideComponent implements OnInit, AfterViewInit{
@ViewChild('el', { static: true}) map: ElementRef;
constructor() {
}
ngOnInit(): void {
}
ngAfterViewInit(){
console.log(this.map.nativeElement);
}
}
html element
<div class="carousel_track_container" #el></div>