After struggling with accessing @ViewChild
in constructor I've come to an observation I do not understand. It had quite important consequences in my app.
Simplified app.component.ts
code to demonstrate the point:
export class MyApp {
myProp: string;
constructor() {
console.log( this ); //line A
console.log( this.myProp ); //line B
this.myProp = 'my string'; //line C
}
Question is: why does line A
output the whole app object WITH myProp
set to 'my string'
while line B
shows myProp
as undefined
?
In line A this
should have myProp
as undefined
as well since it is only set in line C
.
It is all against code order..