【发布时间】:2020-02-07 07:09:57
【问题描述】:
我曾经在 Angular 6 中使用 console.log 来查看浏览器中变量的内容
console.log('CONSOLOG: M:paginateVar & O: this.var : ', this.var);
...我对此很满意,但现在我开始使用 Angular 8 并且出现此错误(当我 npm start 时):
No type errors found
Version: typescript 3.4.5
Time: 2104ms
× 「wdm」: 1029 modules
ERROR in ./src/main/webapp/app/home/home.component.ts
Module Error (from ./node_modules/eslint-loader/dist/cjs.js):
D:\JHipster\spingular\src\main\webapp\app\home\home.component.ts
105:7 error Unexpected console statement no-console
✖ 1 problem (1 error, 0 warnings)
i 「wdm」: Failed to compile.
如何在浏览器中查看变量的内容?
TSLINT:
{
"rulesDirectory": ["node_modules/codelyzer"],
"rules": {
"no-console": [false, "debug", "info", "time", "timeEnd", "trace" ],
"directive-selector": [true, "attribute", "jhi", "camelCase"],
"component-selector": [true, "element", "jhi", "kebab-case"],
"no-inputs-metadata-property": true,
"no-outputs-metadata-property": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-output-rename": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": false,
"component-class-suffix": true,
"directive-class-suffix": true
}
}
【问题讨论】:
-
这是一个需要修改的 linting 规则,而不是 angular。 palantir.github.io/tslint/rules/no-consoleeslint.org/docs/rules/no-console
-
即使您像人们建议的那样关闭 lint 规则,在生产版本中看到控制台垃圾邮件也是非常糟糕的。如果
environment.production= true,我建议在生产版本中从 main.ts 剥离它们,或者至少将它们包装在 isDevMode
标签: angular