I want to give it some delay before calling the redirect URL in order to allow to store the needed data.
How can this be achieved?
To delay a function call, use setTimeout() function. functionname − The function name for the function to be executed. milliseconds − The number of milliseconds. arg1, arg2, arg3 − These are the arguments passed to the function.
await new Promise(f => setTimeout(f, 1000)); Please note, that you can use await only inside async function. setTimeout( () => { /*Your Code*/ }, Milliseconds );
Simple solution is to use Router Service to redirect and setTimeout function for delay
gotToPage() : void {
// something
setTimeout(() => this._router.navigateByUrl('url'),2500); // 2500 is millisecond
}
You have such decorator in the utils-decorators (npm install --save utils-decorators
) lib:
import {delay} from 'utils-decorators';
class SomeComponent {
@delay(1000)
func(): any {
....
}
}
You will find other very useful decorators there, such as debounce, throttle and many more.
https://vlio20.github.io/utils-decorators/#delay
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