Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Angular 2 Typescript application

How to debug Angular 2 Typescript application using visual code or with the developer tools?

like image 307
Lasantha Basnayake Avatar asked Aug 31 '26 04:08

Lasantha Basnayake


1 Answers

Late to the party, but hope the following helps someone else. The solution will work for angular2 & angular4 = Angular on visual studio code.

  1. Install new extension - Debugger for Chrome enter image description here

  2. A new folder will be created (automagically) under your project - '.vscode' -> 'launch.json'. enter image description here

  3. Edit 'launch.json' to reflect as below. Note, port 4200 is default to 'ng serve' adjust if yours is different.

    {
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:4200",
            "webRoot": "${workspaceRoot}",
            "sourceMaps": true
        },
        {
            "type": "chrome",
            "request": "attach",
            "name": "Attach to Chrome",
            "port": 9222,
            "webRoot": "${workspaceRoot}",
            "sourceMaps": true
        }
    ]
   }
  1. Finally we get to 'play' - click on 'debug' followed by clicking on the 'play' button (see below). From there a debug chrome window will open up, view console to see your console.log outputs.

enter image description here

HAPPY CODING! :-)

like image 58
Rodrigo Rubio Avatar answered Sep 02 '26 05:09

Rodrigo Rubio