Angular ViewChild Reference undefined

I ran into this the other day. I had a ViewChild reference and after initializing the ViewChild reference was undefined. This was understandable as I'd made an update to wrap the ViewChild reference in an ngIf which was not resolved.

This posed the question as to what happens when the ngIf resolves, does the ViewChild reference get set then and, of course, it does.

In my scenario I needed to do some custom logic when the value is set and so added a set function to the ViewChild refernence.

Anywho, here's the stackblitz link