1 of 59

Modern Web with

Angular 2

As a Platform

Anas Raza Firdousi

@AnasFirdousi

PayPal

2 of 59

3 of 59

Single Page Application

4 of 59

Traditional Web Applications

Browser

Server

Initial Request

HTML Response

1

Form POST

HTML Response

2

5 of 59

Ajax Based Application

Browser

Server

Initial Request

HTML Response + JavaScript Code

1

Ajax

XML / JSON

Ajax

XML / JSON

2

3

$.get(“ . . . “)

$.post(“ . . . “)

Processing

6 of 59

XMLHttpRequest $.get(“...”)

XMLHttpResponse $.post(“...”)

Ajax Based Application

7 of 59

Single Page Application

Browser

Server

Initial Request

HTML Response + Angular App

1

Http Request

JSON / Resource Files

Http Request

JSON / Resource Files

2

3

$.get(“ . . . “)

$.post(“ . . . “)

Minimal

Processing

Templating & Rendering

+

Major Processing

Static File Server

+

Data Endpoints

+

Business Validations

8 of 59

Library, Framework & Platforms

9 of 59

What’s a library?

Suite of pre-written code

Provides utility functions

Platform agnostic

Quick DOM Traversal

Easy DOM Manipulation

Simple DOM Event Handling

Ajax

. . .

? Modularity

? App State Management

? Data Flow Management

10 of 59

Write less, creates a lot of mess

11 of 59

What’s a framework?

A lot of stuff libraries do

Modularity

App State Management

Data Flow Management

Testing

12 of 59

What’s a platform?

A lot of stuff libraries do

A lot of stuff frameworks do

Languages & Tooling

Cross Platform & Cross Domain

Out-of-the-box feature support

Much more . . .

13 of 59

Angular 2 as a Platform

14 of 59

Angular 2 as a Platform

Language

JS (ES5)

JS (ES6)

TypeScript

Dart

Modularization

DI

Lazy Load

Decorators

Zones

Render

Optimize

Compile

Change

Render

Cross Domain

Browser

Server

Mobile

Desktop

Tooling

CLI

Augury

TS Tools

Codeylzer

More . . .

FRP

Offline

PWA

Native

15 of 59

1

0.5

0

Angular 1

Oct 2015

Angular 1

May, 2016

Angular 2

May 2016

1.1M

1.3M

360K

Based on 30-day active visitors to Angular docs

Are people really using it ?

16 of 59

Inside an Angular 2 App

17 of 59

Breaking the UI into Components

18 of 59

Breaking the UI into Components

Footer

List

Header

Search

App

H

S

L

F

Op

LI

LI

LI

19 of 59

Keys of an Angular 2 App

20 of 59

App

H

S

L

F

Op

LI

LI

LI

Server

// footer.ts

@Component({

})

export class Footer {

constructor(){

}

onClick() {

}

}

// footer.ts

@Component({

})

export class Footer {

constructor(){

}

onClick() {

}

}

// footer.ts

@Component({

})

export class Footer {

constructor(){

}

onClick() {

}

}

// footer.ts

@Component({

})

export class Footer {

constructor(){

}

onClick() {

}

}

Service 1

Service 2

Service 3

Service 4

Service 5

DI

Data Binding

Templating

Http

Routing

. . .

Component

Services

Dependency Injection

//todoservice.ts

@Injectable()

export class TodoService{�

todos:Todos[] = [];

getTodos(){

Return this.todos;

}

�}

//todoservice.ts

@Injectable()

export class TodoService{

todos:Todo[] = [];

getTodos(){

Return this.todos;

}

}

//todoservice.ts

@Injectable()

export class TodoService{

todos:Todo[] = [];

getTodos(){

return this.todos;

}

}

//todoservice.ts

@Injectable()

export class TodoService{

todos:Todo[] = [];

getTodos(){

return this.todos;

}

}

21 of 59

Component

Dependency Injection

Services

Template

Data Binding

Directive

+

+

Pipes

Custom Pipes

22 of 59

Event & Data Flow

Top to Bottom

Bottom to Top

Event & Data Flow

Top to Bottom

Bottom to Top

Event & Data Flow

Top to Bottom

Bottom to Top

[ data ]

data

data

data

data

23 of 59

Event & Data Flow

Top to Bottom

Bottom to Top

Event & Data Flow

Top to Bottom

Bottom to Top

Event & Data Flow

Top to Bottom

Bottom to Top

( event )

event

event

event

24 of 59

Let’s live code?

25 of 59

Caution !

26 of 59

github.com/afirdousi/ipc-2016-angular2-app

Go play with it!

27 of 59

What we just saw?

28 of 59

Angular 2 : Building blocks

Service

Data & Event Flow

Component

Templating

DI

Pipes

29 of 59

Angular 2 Show-stoppers

30 of 59

Performance

Productivity

Versatility

31 of 59

Compiler Optimizaton

HTML Template

Deploy

HTML Template

Optimized JavaScript

Deploy

Template Compiler

32 of 59

Size of Application

200

150

100

50

0

Angular 2

Angular 1

Angular 2

NOW

170K

56K

45K

33 of 59

Your Code

How to split?

Lazy Loading

34 of 59

1

4

3

2

Via routes!

Lazy Loading

35 of 59

1

Route 1

Lazy Loading

36 of 59

2

Route 2

Lazy Loading

37 of 59

Angular Universal

38 of 59

Performance

Productivity

Versatility

39 of 59

augury.angular.io

40 of 59

41 of 59

42 of 59

cli.angular.io

43 of 59

Workflow Automation: Angular CLI

Create Project

Generate Components

Dev Server

Deploy!

Scaffold Tests

Lint & Format

Generate Routes

Run Tests

Preprocess CSS

Deployment Build

44 of 59

Previously...

Create a project directory

Write a tsconfig.json file

Write a typings.json file

Write a package.json file

Install packages

Create folder structure

Write app.component.ts

Write main.ts

Write index.html

Write style.css

npm start

45 of 59

With Angular CLI...

ng new AwesomeApp

cd AwesomeApp

ng serve

46 of 59

angular.io/styleguide

47 of 59

48 of 59

3rd Party UI Toolkits - For Angular

http://valor-software.com/ng2-bootstrap/

https://github.com/primefaces/primeng

49 of 59

material.angular.io

50 of 59

Performance

Productivity

Versatility

51 of 59

Unified Development

52 of 59

Mobile Development

mobile.angular.io

53 of 59

Native Mobile Apps

54 of 59

Installed Desktop

Chrome

Node

Electron

HTML + JS

Win/Mac/Linux

Menus, notifications, etc.

55 of 59

Installed Desktop

Chrome

Node

Electron

Faster

Platform APIs

Auth, DB, hardware

56 of 59

Angular 2 is not a library

Angular 2 is not a framework

Angular 2 is a platform

57 of 59

Angular 2 -

Onsite On-Demand Training

bit.ly/ng-training-onsite

bit.ly/request-ng-training

Code: IPC2016

58 of 59

Thanks!

@AnasFirdousi

anasfirdousi.com

59 of 59

inj

inj

inj

inj

inj

inj

inj

inj

inj

I want “UserService”

I dont have “UserService”

“UserService”

inj

inj

“UserService”

User

Service

User

Service

inj

User

Service

inj

User

Service

inj

User

Service

User

Service

inj

User

Service

inj

User

Service

inj

User

Service

inj

inj

“UserService”

User

Service

User

Service

inj

User

Service

inj

User

Service

inj

User

Service

User

Service

inj

User

Service

inj

User

Service

inj

User

Service