This Angular app consists of only app-root
component with a single <div>
and a <button>
.
When a button is clicked the onClick()
function logs to console the div_a
object with:
console.log("...onClick() div_a:", this.div_a);
with div_a
defined with following statement:
@ViewChild('div_a', { static: false }) div_a: Component;
Question: why both the ngOnInit
and constructor
functions logs that the div_a
is undefined? How to fix the problem of these functions of not being able to use div_a
object?
Below is the link to Stackblitz project (please note that the GitHub branch that is linked to this stackblitz
project needs to be switched from master
to qViewChild
branch).
https://stackblitz.com/edit/angular-r9hwbs?file=src%2Fapp%2Fwidget-a%2Fwidget-a.component.html