Top Banner
DEBUGGING AN ANGULAR APP Laurent Duveau July 5th, 2017
36

Debugging an Angular App

Jan 23, 2018

Download

Technology

Laurent Duveau
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Debugging an Angular App

DEBUGGING AN ANGULAR APP Laurent Duveau

July 5th, 2017

Page 2: Debugging an Angular App

WHO AM I ?

Laurent Duveau

I live in Montreal, Canada

Founder of the Angular Academy

2-day Angular Classroom Training

68 classes in the last 18 months

Montreal, Boston, Quebec, Toronto,Vancouver, Ottawa, Calgary, London, Copenhagen…

@LaurentDuveau

2

September!

Page 3: Debugging an Angular App

AGENDA

3

Use TypeScript!

Tip: Json pipe

Angular Language Service

Debug your code!

Augury

Master the Console

Debug RxJS

Page 4: Debugging an Angular App

“Debugging is twice as hard

as writing the code in the

first place. Therefore, if you

write the code as cleverly as

possible, you are, by

definition, not smart enough

to debug it.”- Brian Kernighan

Page 5: Debugging an Angular App

When everything fails…

Page 6: Debugging an Angular App

Demonstration

Page 7: Debugging an Angular App

Use TypeScript!

Page 8: Debugging an Angular App

TYPESCRIPT…

Is not really something brand new to learn

It is just typed JavaScript (fully compatible with Js ecosystem)

Is used to generate your Js

Easily learnable for Java or C# developers

Latest ES (classes, modules,…) + types, interfaces, generics, enums, async/await, …

Page 9: Debugging an Angular App

ERRORS AT COMPILE-TIME!

var a = 54a.trim()

TypeError: undefinedis not a function

var a: string = 54a.trim()

Cannot convert‘number’ to ‘string’

JavaScript TypeScript

runtime… compile-time!

Page 10: Debugging an Angular App

“TypeScript? It’s like

coding JavaScript but

without the pain”- Someone on Hacker News

Page 11: Debugging an Angular App

Demonstration

Page 12: Debugging an Angular App

Json pipe

Page 13: Debugging an Angular App

USE THE JSON PIPE!

component.template.html

<li [title]="product">{{ product.name }}

</li>

Page 14: Debugging an Angular App

USE THE JSON PIPE!

component.template.html

<li [title]="product | json">{{ product.name }}

</li>

Page 15: Debugging an Angular App

Demonstration

Page 16: Debugging an Angular App

Angular Language Service

Page 17: Debugging an Angular App

ANGULAR LANGUAGE SERVICE

Editor extension to get validation and autocompletion in your html templates.

Page 18: Debugging an Angular App

Demonstration

Page 19: Debugging an Angular App

Debug your code!

Page 20: Debugging an Angular App

DEBUG YOUR CODE!

Just F12 / Sources tab in your browser

Or

Debugger for Chrome extension!

Page 21: Debugging an Angular App

tsconfig.json

{

"compilerOptions": {

"target": "es5",

"module": "system",

"moduleResolution": "node",

"sourceMap": true,

"emitDecoratorMetadata": true,

"experimentalDecorators": true,

"removeComments": false,

"noImplicitAny": true,

"suppressImplicitAnyIndexErrors": true,

"allowJs": true

}

}

TSCONFIG.JSON

Map files for live

debugging!

Page 22: Debugging an Angular App

Demonstration

Page 23: Debugging an Angular App

Augury

Page 24: Debugging an Angular App

AUGURY

A Google Chrome Dev Tools extension for debugging Angular applications.

Install the extension from Chrome Web Store

24

http://augury.angular.io/

Page 25: Debugging an Angular App

Demonstration

Page 26: Debugging an Angular App

Master the console

Page 27: Debugging an Angular App

CONSOLE

> console.log()

> console.error()

> console.group() / console.groupCollapsed()

> console.groupEnd()

> console.table()

Page 28: Debugging an Angular App

Debug RxJS

Page 29: Debugging an Angular App

DEBUG RXJS

Use the do operator!

getProductById(id: number): Observable<Product> {return this

.getProducts()

.flatMap(product => product)

.filter(p => p.id == id)

.catch(this.handleError);}

Page 30: Debugging an Angular App

DEBUG RXJS

Use the do operator!

getProductById(id: number): Observable<Product> {return this

.getProducts()

.flatMap(product => product)

.filter(p => p.id == id)

.catch(this.handleError);}

Page 31: Debugging an Angular App

DEBUG RXJS

Use the do operator!

getProductById(id: number): Observable<Product> {return this

.getProducts()

.do(console.log)

.flatMap(product => product)

.do(console.log)

.filter(p => p.id == id)

.catch(this.handleError);}

Page 32: Debugging an Angular App

Demonstration

Page 33: Debugging an Angular App

Thank you!

Page 34: Debugging an Angular App

Angular Classroom Training

Page 35: Debugging an Angular App
Page 36: Debugging an Angular App

submit your evaluation online now to win!

WIN FOR EVALUATION!!