I have a problem. I want to use setTimeout
in angular to call a function after 2 second but I get this:
ERROR: Module not found: Error: Can't resolve 'timers'; this is my function:
login(user) {
console.log(user.value);
this.loginService.loginUser(user.value);
// this.user = this.loginService.getUser();
setTimeout(() => {
this.user = this.loginService.getUser();
}, 2000);
if (this.user === undefined) {
console.log('username or password incorrect');
} else {
console.log(this.user);
this.navbar.connectComps(this.user);
this.navbar.getCheck();
}
}
Please tell me what should I do to solve this issue.
I got the same error when I used setTimeout. turns out angular added the following line without me realizing it. Once I removed it, everything started to work again.
// remove this import
import { setTimeout } from 'timers';
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