How To Debug An Angular Application In Chrome

Create a basic application or open any existing angular app in visual studio code. I have created a basic application and opened the same project in VS code.
 
How To Debug An Angular Application In Chrome
 
I changed the default app.component.html with the following code, this will create a UI with two textboxes. Just for an example, I'll  add (sum) two values with doSum() function in App.component.ts, so that I can put a breakpoint to test the debugging.
 
App.Component.html
  1. <div>  
  2.   <h1>Basic App for testing debugging in chrome</h1>  
  3.   <p>Value 1 <input type="number" placeholder="Enter Value 1" [(ngModel)]="val1"></p>  
  4.   <p>Value 1 <input type="number" placeholder="Enter Value 2" [(ngModel)]="val2"></p>  
  5.   <p><input type="button" value="Sum" (click)="doSum()"></p>  
  6.   <p>Total: {{total}}</p>  
  7. </div>  
App.component.ts
  1. export class AppComponent {  
  2.   title = 'debuggingApp';  
  3.   val1:number;  
  4.   val2:number;  
  5.   total:number;  
  6.   public doSum()  
  7.   {  
  8.     this.total=this.val1+this.val2;  
  9.   }  
  10. }  
After editing your default code of App component, serve your app with the following Angular CLI command.
 
How To Debug An Angular Application In Chrome
 
This will be your output after changes.
 
How To Debug An Angular Application In Chrome
 
Now we need a Google chrome debugger extension for Visual Studio code, so click on extension option at left side icon of VS code.
 
How To Debug An Angular Application In Chrome
 
Write “debugger for chrome” in the search box and I hope you’ll get the same list as in the following image. Select the first one and click on the install option in details page at right side.
 
How To Debug An Angular Application In Chrome
 
Now go to the line that you want to debug when this  executes. Now click at to the left of this line or press F9 to add a breakpoint in this line.
 
How To Debug An Angular Application In Chrome
 
Or you can find the debug option from the top menu of VS code and select the debugging breakpoint options that suit  your requirement.
 
How To Debug An Angular Application In Chrome
 
Now Press F5 or start the debugging option from the debug menu.
 
How To Debug An Angular Application In Chrome
 
The first time for debugging we have to select the debugging environment. For Visual Studio code debugging setting, Select Chrome.
 
How To Debug An Angular Application In Chrome
 
Once you set your debugging environment it’ll set in launch.json, this file is just for local not for production.

Change your port number in URL option where your application is working, like the default port number is 4200.
 
How To Debug An Angular Application In Chrome
 
Now press F5 one more time and you’ll see this will launch a new Chrome with the same URL that you set in launch.json.
 
Enter the values and click to the button. This will automatically enable that breakpoint in App.component.ts.
 
How To Debug An Angular Application In Chrome
 
You check your inputs at the code.
 
How To Debug An Angular Application In Chrome
 
Press continue in debug tool to submit this statement or next breakpoint.
 
Thanks, I hope this will help you.