Slide 1

Slide 1 text

Building Universal Applications with Angular 2 Minko Gechev github.com/mgechev twitter.com/mgechev blog.mgechev.com

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

github.com/mgechev twitter.com/mgechev blog.mgechev.com

Slide 4

Slide 4 text

Agenda What is Angular? What’s wrong with Angular 2? Introduction to Angular 2 Why Angular 2 is awesome? Should I use Angular 2 in my next project?

Slide 5

Slide 5 text

Agenda What is Angular 2? What’s wrong with Angular 2? What are the core concepts of Angular 2? Why Angular 2 is awesome? Should I use Angular 2 in my next project?

Slide 6

Slide 6 text

Agenda What is Angular 2? What’s wrong with Angular 2? What are the core concepts of Angular 2? Why Angular 2 is awesome? Should I use Angular 2 in my next project?

Slide 7

Slide 7 text

Agenda What is Angular 2? What’s wrong with Angular 2? What are the core concepts of Angular 2? Why Angular 2 is awesome? Should I use Angular 2 in my next project?

Slide 8

Slide 8 text

Agenda What is Angular 2? What’s wrong with Angular 2? What are the core concepts of Angular 2? Why Angular 2 is awesome? Should I use Angular 2 in my next project?

Slide 9

Slide 9 text

Agenda What is Angular 2? What’s wrong with Angular 2? What are the core concepts of Angular 2? Why Angular 2 is awesome? Should I use Angular 2 in my next project?

Slide 10

Slide 10 text

What is Angular 2?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Core concepts of Angular 2 • Directives • Components • Pipes • Services • Dependency Injection

Slide 14

Slide 14 text

Directives

Slide 15

Slide 15 text

Primitive used for encapsulation of basic UI related logic

Slide 16

Slide 16 text

tooltip.ts @Directive({ selector: '[tooltip]', inputs: ['tooltip'], host: { '(mouseenter)': 'onMouseEnter()', '(mouseleave)': 'onMouseLeave()' } }) export class Tooltip { private overlay:Overlay; private tooltip:string; constructor(private el:ElementRef, manager: OverlayManager) { this.el = el; this.overlay = manager.get(); } onMouseEnter() { this.overlay.open(this.el, this.tooltip); } onMouseLeave() { this.overlay.close(); } }

Slide 17

Slide 17 text

tooltip.ts @Directive({ selector: '[tooltip]', inputs: ['tooltip'], host: { '(mouseenter)': 'onMouseEnter()', '(mouseleave)': 'onMouseLeave()' } }) export class Tooltip { private overlay:Overlay; private tooltip:string; constructor(private el:ElementRef, manager: OverlayManager) { this.el = el; this.overlay = manager.get(); } onMouseEnter() { this.overlay.open(this.el, this.tooltip); } onMouseLeave() { this.overlay.close(); } }

Slide 18

Slide 18 text

tooltip.ts @Directive({ selector: '[tooltip]', inputs: ['tooltip'], host: { '(mouseenter)': 'onMouseEnter()', '(mouseleave)': 'onMouseLeave()' } }) export class Tooltip { private overlay:Overlay; private tooltip:string; constructor(private el:ElementRef, manager: OverlayManager) { this.el = el; this.overlay = manager.get(); } onMouseEnter() { this.overlay.open(this.el, this.tooltip); } onMouseLeave() { this.overlay.close(); } }

Slide 19

Slide 19 text

Wait a minute… this looks like Java

Slide 20

Slide 20 text

Angular 2 is written in TypeScript

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

TypeScript is…

Slide 24

Slide 24 text

superset of ECMAScript

Slide 25

Slide 25 text

optional type checking

Slide 26

Slide 26 text

open source

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

…you can still use ES5…

Slide 29

Slide 29 text

tooltip.js var Tooltip = ng.Directive({ selector: '[tooltip]', inputs: ['tooltip'], host: { '(mouseenter)': 'onMouseEnter()', '(mouseleave)': 'onMouseLeave()' } }) .Class({ constructor: [ng.Inject(ng.ElementRef), ng.Inject(OverlayManager), function (tooltip, el, manager) { this.el = el; this.overlay = manager.get(tooltip); }], onMouseEnter() { this.overlay.open(this.el, this.tooltip); }, onMouseLeave() { this.overlay.close(); } });

Slide 30

Slide 30 text

tooltip.js var Tooltip = ng.Directive({ selector: '[tooltip]', inputs: ['tooltip'], host: { '(mouseenter)': 'onMouseEnter()', '(mouseleave)': 'onMouseLeave()' } }) .Class({ constructor: [ng.Inject(ng.ElementRef), ng.Inject(OverlayManager), function (tooltip, el, manager) { this.el = el; this.overlay = manager.get(tooltip); }], onMouseEnter() { this.overlay.open(this.el, this.tooltip); }, onMouseLeave() { this.overlay.close(); } });

Slide 31

Slide 31 text

tooltip.js var Tooltip = ng.Directive({ selector: '[tooltip]', inputs: ['tooltip'], host: { '(mouseenter)': 'onMouseEnter()', '(mouseleave)': 'onMouseLeave()' } }) .Class({ constructor: [ng.Inject(ng.ElementRef), ng.Inject(OverlayManager), function (tooltip, el, manager) { this.el = el; this.overlay = manager.get(tooltip); }], onMouseEnter() { this.overlay.open(this.el, this.tooltip); }, onMouseLeave() { this.overlay.close(); } });

Slide 32

Slide 32 text

Components

Slide 33

Slide 33 text

Directives with views

Slide 34

Slide 34 text

hello-world.ts @Component({ selector: 'hello-world', template: '

Hello, {{this.target}}!

' }) class HelloWorld { target:string; constructor() { this.target = 'world'; } }

Slide 35

Slide 35 text

hello-world.ts @Component({ selector: 'hello-world', template: '

Hello, {{this.target}}!

' }) class HelloWorld { target:string; constructor() { this.target = 'world'; } }

Slide 36

Slide 36 text

hello-world.ts @Component({ selector: 'hello-world', template: '

Hello, {{this.target}}!

' }) class HelloWorld { target:string; constructor() { this.target = 'world'; } }

Slide 37

Slide 37 text

Pipes

Slide 38

Slide 38 text

Encapsulate the data transformation logic

Slide 39

Slide 39 text

lowercase-pipe.ts @Pipe({ name: 'lowercase' }) class LowerCasePipe implements PipeTransform { transform(value: string): string { if (!value) return value; if (typeof value !== 'string') { throw new Error('Invalid pipe value', value); } return value.toLowerCase(); } }

Slide 40

Slide 40 text

Services

Slide 41

Slide 41 text

Simply, ES2015 classes which can be wired together with…

Slide 42

Slide 42 text

Dependency Injection

Slide 43

Slide 43 text

di.ts import { provide, Injector, Injectable } from 'angular2/angular2'; class Http {} @Injectable() class DataMapper { constructor(private http: Http) {} } let injector = Injector.resolveAndCreate([ provide(Http, { useValue: new Http() }), DataMapper ]); injector.get(DataMapper);

Slide 44

Slide 44 text

di.ts import { provide, Injector, Injectable } from 'angular2/angular2'; class Http {} @Injectable() class DataMapper { constructor(private http: Http) {} } let injector = Injector.resolveAndCreate([ provide(Http, { useValue: new Http() }), DataMapper ]); injector.get(DataMapper);

Slide 45

Slide 45 text

di.ts import { provide, Injector, Injectable } from 'angular2/angular2'; class Http {} @Injectable() class DataMapper { constructor(private http: Http) {} } let injector = Injector.resolveAndCreate([ provide(Http, { useValue: new Http() }), DataMapper ]); injector.get(DataMapper);

Slide 46

Slide 46 text

di.ts import { provide, Injector, Injectable } from 'angular2/angular2'; class Http {} @Injectable() class DataMapper { constructor(private http: Http) {} } let injector = Injector.resolveAndCreate([ provide(Http, { useValue: new Http() }), DataMapper ]); injector.get(DataMapper);

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Now you know the basics!

Slide 52

Slide 52 text

Lets take a step back…

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Angular 2 is platform agnostic

Slide 56

Slide 56 text

Not coupled with DOM, even HTML

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

…and even more…

Slide 59

Slide 59 text

Client Server

Slide 60

Slide 60 text

Client Server

Slide 61

Slide 61 text

Client Server GET / GET * loop

Slide 62

Slide 62 text

Client Server GET / GET * loop Running JavaScript

Slide 63

Slide 63 text

Client Server GET / GET * loop GET * loop

Slide 64

Slide 64 text

Client Server GET / GET * loop GET * loop

Slide 65

Slide 65 text

server-side rendering

Slide 66

Slide 66 text

Client Server

Slide 67

Slide 67 text

Client Server

Slide 68

Slide 68 text

Client Server GET /

Slide 69

Slide 69 text

Client Server GET / Running JavaScript

Slide 70

Slide 70 text

Client Server GET / GET * loop

Slide 71

Slide 71 text

Client Server GET / GET * loop Running JavaScript

Slide 72

Slide 72 text

Client Server GET / GET * loop

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Change detection can be run into separate process

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

so…what’s wrong with Angular 2?

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

Google

Slide 82

Slide 82 text

Google Angular 1

Slide 83

Slide 83 text

Angular 2 Google Angular 1

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

Angular 2 is…

Slide 87

Slide 87 text

rewritten from scratch

Slide 88

Slide 88 text

…developed in a different language

Slide 89

Slide 89 text

…completely incompatible API

Slide 90

Slide 90 text

…brand new building blocks

Slide 91

Slide 91 text

Why?

Slide 92

Slide 92 text

Web have moved forward

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

WebWorkers

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

Learnt lessons

Slide 99

Slide 99 text

Mutable state

Slide 100

Slide 100 text

Tangled data-flow

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

…we will make the transition process boring…

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

ngUpgrade

Slide 105

Slide 105 text

How to migrate to Angular 2? (2 easy steps)

Slide 106

Slide 106 text

Step 1

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

A B C D E F

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

Step 2

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

Thank you! github.com/mgechev twitter.com/mgechev blog.mgechev.com