如何配置Angular和VSCode以使断点工作?

推荐答案

使用Angular 5/CLI 1.5.5测试

  1. 安装Chrome Debugger Extension
  2. 创建launch.json(在.vscode文件夹内)
  3. 使用我的launch.json(见下文)
  4. 创建tasks.json(在.vscode文件夹内)
  5. 使用我的tasks.json(见下文)
  6. CTRL+Shift+B
  7. 按F5键

launch.json for angular/cli >= 1.3

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (Test)",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:9876/debug.html",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (E2E)",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
      "protocol": "inspector",
      "args": ["${workspaceFolder}/protractor.conf.js"]
    }
  ]
}

tasks.json for angular/cli >= 1.3

{
    "version": "2.0.0",
    "tasks": [
      {
        "identifier": "ng serve",
        "type": "npm",
        "script": "start",
        "problemMatcher": [],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      },
      {
        "identifier": "ng test",
        "type": "npm",
        "script": "test",
        "problemMatcher": [],
        "group": {
          "kind": "test",
          "isDefault": true
        }
      }
    ]
  }

测试Angular 为2.4.8

  1. 安装Chrome Debugger Extension
  2. 创造launch.json
  3. 使用我的launch.json(见下文)
  4. 启动NG Live Development服务器(ng serve)
  5. 按F5键

launch.json for angular/cli >= 1.0.0-beta.32

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "userDataDir": "${workspaceFolder}/.vscode/chrome",
      "runtimeArgs": [
        "--disable-session-crashed-bubble"
      ]
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "port": 9222,
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true
    }
  ]
}

launch.json for angular/cli < 1.0.0-beta.32

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Lunch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}/src/app",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${workspaceFolder}/node_modules/*",
        "webpack:///./src/*": "${workspaceFolder}/src/*"
      },
      "userDataDir": "${workspaceFolder}/.vscode/chrome",
      "runtimeArgs": [
        "--disable-session-crashed-bubble"
      ]
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "port": 9222,
      "webRoot": "${workspaceFolder}/src/app",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${workspaceFolder}/node_modules/*",
        "webpack:///./src/*": "${workspaceFolder}/src/*"
      }
    }
  ]
}

Angular相关问答推荐

当通过指令合成添加到组件时,Angular 指令@ Investment被忽略

文件阅读器未正确给出某些CSV文件的结果

*ngFor循环中令人困惑的Angular 行为

为什么这个拦截器只在发送事件上触发,而不是在实际响应上触发?

如何在投影项目组周围添加包装元素?

在不使用散列(#)路由的情况下刷新Angular 8的SPA时,删除404错误

笔刷Angular 为17

如何重新显示ngbAlert(Bootstrap widgest for Angular)消息后再次驳回它

截获火灾前调用公共接口

Angular 应用程序未在Azure应用程序服务中运行

如何防止变量值重置?

将ngModel绑定到@Input属性是不是一种糟糕的做法?

NG-Zorro Datepicker 手动输入掩码不起作用

如何从2个api获取数据并查看Angular material 表中的数据?

如何在 Angular 中顺序执行回调

我应该在 Jasmine 3 中使用什么来代替 fit 和 fdescribe?

实现自定义 NgbDateParserFormatter 来更改 NgbInputDatepicker 上输入值的格式是否正确?

使用 DomSanitizer 绕过安全性后,安全值必须使用 [property]=binding

默认情况下如何在Angular中 Select mat-button-toggle

Angular 2+ ngModule 中导入/导出的作用