0
I understand you have a few pages about Angular’s Lifecycle, but I haven’t found how to call a function every time the page finishes loading. I have a key that when starting the APP it is set in Storage
this.storage.set('X-Access-Token', 'f27bf5399b81c701bd9d6158ca67bb58');
When I start a few pages it is necessary to take this Key from Storage and call the API to load the data. Calling Storage and API is OK.
export class MyChannelPage implements OnInit {
XAccessToken: any;
constructor(
private httpClient: HttpClient,
private storage: Storage,
){}
ngOnInit() {
this.GetXAccessToken();
this.ConsoleToLog();
}
GetXAccessToken() {
this.storage.get('X-Access-Token').then((token) => {
this.XAccessToken = token;
});
}
ConsoleToLog(){
console.log(this.XAccessToken);
}
}
Problem is that if I call the function to load the data inside ngOnInit(), it returns me Undefined for the variable Xaccesstoken.
I believe it must be some Lifecycle that I need to use instead of ngOnInit();
I created a button to call the function and when I use the button the functions work.
Know which Lifecycle I need to use so that whenever the page is loaded the data will be updated?
But you’ve tried some Lifecycle?
– LeAndrade
@Leandrade tried a little with ngOnInit(), ngAfterViewChecked() and ngAfterContentView() but I was unsuccessful.
– RRV