Slide 1

Slide 1 text

Introduction to Angular 2 Shuhei Kagawa Dec 14, 2015 #tkjs

Slide 2

Slide 2 text

Who are you? • Shuhei Kagawa • Front/Back-end developer @ M3, Inc. • Rails/Angular.js/Node.js • Building SPA >10000 lines of JavaScript

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Choosing JS framework is hard

Slide 6

Slide 6 text

What I wanted 1.5 years • Data-binding (less boilerplate) • Amount of learning resources (for team development) • (Seemingly) Long-time support • Rich standard libraries (security, validation and etc.)

Slide 7

Slide 7 text

https://www.google.com/trends/

Slide 8

Slide 8 text

http://www.bennadel.com/blog/2439-my-experience-with-angularjs---the-super-heroic-javascript-mvw-framework.htm

Slide 9

Slide 9 text

Piled up APIs since 2009 https://en.wikipedia.org/wiki/File:Quebrada_de_Cafayate,_Salta_(Argentina).jpg

Slide 10

Slide 10 text

Angular: The Good Parts • Directive > Controller • Don't rely on scope inheritance • Directive API (controllerAs, bindToController)

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Angular 2 • Thrown away outdated/unintuitive APIs • Completely rewritten with

Slide 13

Slide 13 text

What is Angular 2 like? • It's coming up soon(?) • Better syntax • Best-in-class performance • Cutting-edge architecture

Slide 14

Slide 14 text

alpha.53 Weekly Breaking Changes

Slide 15

Slide 15 text

beta is coming soon... Less Breaking Changes

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Adoption at Google 100s developers
 Millions LOC

Slide 18

Slide 18 text

Better syntax • TypeScript is the first language (no more JS quirks) • Consistent template syntax • Scoped CSS • ES6 Modules (no more own module system)

Slide 19

Slide 19 text

Languages ES5 ES6 TypeScript Dart

Slide 20

Slide 20 text

ES6 Modules Class Decorator Class property import { Component, Injectable } from 'angular2/core'; @Injectable() class Hero { id: number; name: string; } @Component({ selector: 'my-app', templateUrl: './my-app.html', styleUrls: ['./my-app.css'] }) export class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; public selectedHero: Hero; onSelect(hero: Hero) { this.selectedHero = hero; } getSelectedClass(hero: Hero) { return { selected: hero === this.selectedHero }; } } var HEROES: Hero[] = [ { "id": 11, "name": "Mr. Nice" }, // ... ];

Slide 21

Slide 21 text

{{title}}

My Heroes

  • {{hero.id}} {{hero.name}}

{{selectedHero.name}} details!

id: {{selectedHero.id}}
name:
Text binding Loop Event handler (Seemingly)
 Two-way
 data binding

Slide 22

Slide 22 text

Template syntax • foo="bar" • [foo]="bar" • (foo)="bar()" Plain (passed as a string) Data binding (evaluated as expression) Event handler • ng-include="'hello.tpl'" • ng-href="https://google.com?q={{keyword}}"

Slide 23

Slide 23 text

Best-in-class performance • Ultra-fast change detection • View caching • One-time and offline compilation • (Change detection in Web Worker) • (Server-side rendering (Angular Universal))

Slide 24

Slide 24 text

https://www.youtube.com/watch?v=UxjgUjVpe24 http://info.meteor.com/blog/comparing-performance-of-blaze-react-angular-meteor-and-angular-2-with-meteor

Slide 25

Slide 25 text

https://www.youtube.com/watch?v=UxjgUjVpe24 http://info.meteor.com/blog/comparing-performance-of-blaze-react-angular-meteor-and-angular-2-with-meteor

Slide 26

Slide 26 text

Cutting-edge Architecture • Component-based • Uni-directional data flow • Rx.js built-in • Compatible with Immutable.js

Slide 27

Slide 27 text

import { Component } from 'angular2/core'; import { Control } from 'angular2/common'; import { Jsonp, JSONP_PROVIDERS } from 'angular2/http'; import { bootstrap } from 'angular2/platform/browser'; import { GitHubService } from './github-service'; @Component({ selector: 'my-app', templateUrl: 'app/my-app.html', styleUrls: ['app/my-app.css'] }) export class MyApp { searchText = new Control(); repos: any; constructor(private github: GitHubService) { this.repos = this.searchText.valueChanges .debounceTime(300) .flatMap(text => this.github.search(text)); ; } } bootstrap(MyApp, [JSONP_PROVIDERS, GitHubService]);

Slide 28

Slide 28 text

GitHub repositoy search

Slide 29

Slide 29 text

import { Injectable } from 'angular2/core'; @Injectable() export class GitHubService { constructor(private jsonp: Jsonp) {} search(keyword) { return this.jsonp.get(`https://api.github.com/ search/repositories?callback=JSONP_CALLBACK&q=$ {keyword}&sort=stars`) .map(res => res.json()['data']['items']); } }

Slide 30

Slide 30 text

Upgrade from 1.x • Componentize everything • ngUpgrade • Mix ng1 components and ng2 components • ngForward • Write ng1 app with ng2 syntax

Slide 31

Slide 31 text

Libraries • ng1 libraries doesn't work on ng2 • But people started re-building popular ones with ng2 • ionic2, angular2_material, ng2-bootstrap, ng2- select and etc.

Slide 32

Slide 32 text

Browser support

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

More resources • angular.io • github.com/AngularClass/awesome-angular2 • egghead.io Angular 2 Lessons • gitter.im/angular/angular

Slide 35

Slide 35 text

Thanks! • shuhei@gihtub&npm • shuheikagawa@twitter