首页 > 解决方案 > 错误:您应该使用 $timeout 服务而不是默认的 window.setTimeout 方法

问题描述

我在我的项目中使用 Angular 12 版本。

我使用了 setTimeout 函数,如下所示:

setTimeout(() => this.document.location.reload(), 2000);

当我运行时npm run eslintandfix,我收到这样的错误

error You should use the $timeout service instead of the default window.setTimeout method angular/timeout-service

我在 package.json 中更新了 eslint 脚本,如下所示:

"elint": "eslint . --ext .ts",

"elintandfix": "eslint . --ext .ts --fix",

这是我的 package.json EsLint 插件的状态:

"eslint": "^4.19.1",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-plugin-angular": "^4.0.1",
    "eslint-plugin-import": "^2.23.4",
    "eslint-plugin-node": "^5.2.1",

我找不到任何解决方案。请帮帮我。

先感谢您。

标签: angularnpmeslinttypescript-eslintangular12

解决方案


推荐阅读