Property decorator that configures a view query
View queries are set before the ngAfterViewInit callback is called.

import { Component, OnInit,AfterViewInit,  viewChild } from '@angular/core';

@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent implements OnInit, AfterViewInit {

constructor() { }
@ViewChild('addBtn') addBtn:ElementRef;
ngOnInit(): void {
}
ngAfterViewInit() {
// child is set
console.log(this.addBtn.nativeElement)
}

}

<button #addBtn>add</button>

--

--

Ajay Kumar Maheshwari - [Frontend Developer]

Ajay Kumar Maheshwari - [Frontend Developer]

Currently working as UI Frontend Developer I have worked on multiple domains such as E-learning, E-commerce HTML5, CSS3, JavaScript, SASS, Responsive,Angular