I'm still figuring out angular, and I still don't understand somethings.
Let's assume I have this code:
export class test{
testNumber: number;
constructor(private dataService: DataServicesService) { }
someMethod(){
this.dataService.GetNumber().subscribe( res => this.testNumber= res)
console.log(testNumber);
}
ngOnInit(){
}
}
When I first call someMethod()
and I log testNumber
it logs undefined
. The second time, I call it then it logs the value.
Or even if I do it on the ngOnInit()
:
export class test{
testNumber: number;
constructor(private dataService: DataServicesService) { }
ngOnInit(){
this.dataService.GetNumber().subscribe( res => this.testNumber= res)
console.log(testNumber);
}
}
I get undefined
so I still don't know why if the call is before the log it doesn't work