Javascript 未找到 Angular 6 setTimeout 模块:错误:无法解析“计时器”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50651516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular 6 setTimeout Module not found: Error: Can't resolve 'timers'
提问by Ciprian
I have a problem. I want to use setTimeoutin angular to call a function after 2 second but I get this:
我有个问题。我想setTimeout在 2 秒后使用angular 调用一个函数,但我得到了这个:
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.
请告诉我我该怎么做才能解决这个问题。
回答by Tanvir Ather
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.
我在使用 setTimeout 时遇到了同样的错误。结果 angular 在我没有意识到的情况下添加了以下行。一旦我删除它,一切又开始工作。
// remove this import
import { setTimeout } from 'timers';

