I want to call a function executeAfter5secs()
in my home.ts
when home.html
is opened. How do I do this ?
Currently I have added a button on home.html
and on click of it, the function is being called, but I want to be free from the click and want to call it automatically once the page is loaded, but after 5 seconds.
How do I code in home.ts
side, I am bit confused like what do I code inside:
ngOnInit() { }
so that once page is loader time starts and after 5 seconds my function is called.
Add this code in your .ts file
ionViewDidLoad(){
setTimeout(() => {
alert('Hello...')
}, 5000);
}
you need to use 'AfterViewInit' after component's view fully initialized.
in .ts file
export class LoginPage implements AfterViewInit {
ngAfterViewInit(){
setTimeout( ()=>{
console.log('works')
}, 5000)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With