Declaring variable
export class TestComponent implements OnInit {
testVar:string;
then initialising
ngOnInit() {
this.somefunction works.subscribe(
this.testVar='testData';
console.log('log1 '+this.testVar);
);
console.log('log2 '+this.testVar);
}
now firing AfterViewInit:
ngAfterViewInit() {
console.log('log3 '+this.testVar);
The results are
log1 testData
log2 undefined
log3 undefined
question is why log2 and log 3 give undefined testVar and how can I fix that ?