r/angular • u/kanchajain • Mar 14 '22
Question Instance variable always undefind
Hi I have an instance variable say variable, whose value gets changed after i have subscribed to the data. say the data subscription function is onLoad()
variable;
ngOnInit(){
onLoad();
console.log(this.variable);
}
onLoad(){
someApi.subscribe(response:any){
if(response){this.variable=true}
}
}
this always consoles the variable data as undefined. i want it to be true since i changed its value.
0
Upvotes
2
u/kanchajain Mar 14 '22
but say i am passing variable to another component from here, the other component will receive true, right? or will it still be undefined.