简体   繁体   English

无法在Angular构造函数或OnInit中放置断点

[英]Can't put a breakpoint in Angular constructor or OnInit

I have an Angular application, and I am trying to set a breakpoint in F12 tools in Chrome or IE. 我有一个Angular应用程序,我试图在Chrome或IE中的F12工具中设置断点。 I have simple test case: 我有简单的测试用例:

export class LoginComponent implements OnInit {
    message: string;

    constructor(private router: Router) { 
        console.log("Login Constructor");
    }

    ngOnInit() {
        console.log("Login OnInit");
    }
}

I see log output in the console, but setting a breakpoint doesn't work. 我在控制台中看到日志输出,但设置断点不起作用。 I think it stopped working a few days ago (not sure if it was an upgrade of some library, or Windows, or both browsers). 我认为它几天前停止工作(不确定它是某些库,Windows或两种浏览器的升级)。 Don't even know where to start looking. 甚至不知道从哪里开始寻找。 The project is built with webpack, and I am getting to this component via routing: 该项目是使用webpack构建的,我通过路由获取此组件:

const appRoutes: Routes = [
{
    path: '',
    redirectTo: '/login',
    pathMatch: 'full'
},
{
    path: '/login',
    component: LoginComponent
}
...
]

Note, that button click handler breaks as expected. 请注意,按钮单击处理程序按预期中断。

Sometimes it's missing to breakpoint because a debugger doesn't know the location of the source code or the code is executing faster than debugger can imagine a breakpoint. 有时缺少断点,因为调试器不知道源代码的位置,或者代码的执行速度比调试器想象的断点快。 In this case the code is not debuggable. 在这种情况下,代码不可调试。

However you can set breakpoint directly to the transplitted javascript code if you can understand the javascript. 但是,如果您能够理解javascript,则可以将断点直接设置为透明的javascript代码。 Webpack sometimes writes a wrong path to the sources in the map file, so you have a lot troubles to fix them. Webpack有时会在映射文件中写入错误的路径,因此修复它们会遇到很多麻烦。 But this issue outgoing from the original question. 但这个问题从原来的问题传出。 What you have to do is to try a different browser or version of Webpack where the bugs are fixed. 你要做的是尝试修复错误的不同浏览器或Webpack版本。 If you know it a bug you should submit it to the corresponding bugtracking system. 如果您知道它是一个错误,您应该将其提交给相应的错误跟踪系统。

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

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