简体   繁体   English

如何 console.log() 一个 Angular 项目?

[英]How to console.log() an Angular project?

I have been trying to debug an Angular project with console.log() , and I checked my chrome console logging options and made sure that all the levels are enabled, but I still got nothing as an output.我一直在尝试使用console.log()调试一个 Angular 项目,我检查了我的 chrome 控制台日志记录选项并确保所有级别都已启用,但我仍然没有任何输出。

I placed my console.log() in many places in the code, including at the constructor of a class and it still didn't work.我把我的console.log()放在代码的很多地方,包括在一个类的构造函数中,但它仍然没有工作。 I noticed;我注意到; however, that I get an output at the chrome console when I change console.log() to console.error() .但是,我得到的铬控制台输出当我改变console.log()console.error() Any idea how to fix this problem?知道如何解决这个问题吗?

只需尝试在 console.log 中使用硬编码字符串,如“console.log("something") 并检查它是否打印。否则,您也可以将“调试器”放在代码中要暂停应用程序的位置。使用这个将确保控件是否实际进入该代码块。然后按 F12 并运行您的应用程序。

It may possible, Logging level has been enabled.可能,日志级别已启用。 You can look for below given code to disable it.您可以查找下面给定的代码来禁用它。

if (environment.production) {
    enableProdMode();
}`

There might chance, log is disabled on lint level.可能有机会,日志在lint级别被禁用。 When u disable in lint level, on run of ng lint --fix .当你在 lint 级别禁用时,运行ng lint --fix It remove lower log level.它删除较低的日志级别。 Check your tslint config for more info.检查您的tslint config以获取更多信息。

ng lint --fix

More info: Stripping all comments and console.logs with ng build --prod, possible?更多信息: 使用 ng build --prod 剥离所有评论和 console.logs,可能吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM