SlideShare a Scribd company logo
Angular를 활용한 웹 프론트단 개발과
2.0에서 달라진점
고재도
W3C HTML5 Conference 2015
+jeado.ko
haibane84@gmail.com
- “Bitfinder.co” Software Engineer
- “kt” IoT Platform Researcher
- “http://webframeworks.kr” AngularJS Tutorial Contributor
- “Google Developer Group Korea WebTech” Organizer
- “시작하세요 AngularJS wikibooks” Author
Change of Web Frontend
Library Feature-Complete
Framework
MVC
Framework
Component
component?
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
<select>
<input>
<ng-search-icon>
<ng-paper-fab>
<ng-drawer-panel>
<ng-field>
Component
= Building block (LEGO)
= a group of HTML elements
Component is made of two
main parts
- View
- Logic
Components View
<section>
<h4>{{ profile.name }}</h4>
<p> Age - {{ profile.age }}</p>
<button ng-click="save()">Save</button>
</section>
<profile-card profile="profile"></profile-card>
Reusable group of element
Component Logic
A Object/Function - A place to store properties and functions
function ProfileCardCtrl(){
this.profile = new Profile({ name : 'jay' });
this.save = function(){
// ...
}
}
So How ?
React Component
class HeloMessage extends React.Component {
render() {
return <div>Hello {this.props.name}</div>;
}
}
React.render(<HelloMessage name="Jay" />,
mountNode);
Ember Component
App.AppProfileComponent = Ember.Component.extend({
actions: {
hello: function(name) {
console.log("Hello", name);
}
}
});
<!-- app-profile template -->
<h1>{{person.title}}</h1>
<img src={{person.avatar}}>
<p class='signature'>{{person.signature}}</p>
{{app-profile person=currentUser}}
Polymer Component
//////// porot-element.html ////////
<link rel="import"
href="bower_components/polymer/polymer.html">
<script>
Polymer({
is: "proto-element",
ready: function() {
this.textContent = "I'm a proto-element."
}
});
</script>
//////// index.html ////////
</head>
<link rel="import" href="proto-element.html">
</head>
<body>
<proto-element></proto-element>
</body>
Angular Connect, London, October 2015
Angular 2.0
Angular Connect, London, October 2015
2.0.0-alpha.48 (2015-12-05)
My First Component
import {bootstrap, Component} from 'angular2/angular2';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);
//index.html
<my-app>loading...</my-app>
Component
Template
Directive
Controller Component
ng1 ng2
Typescript
• Open Source project from Microsoft Technologies.
• An attempt to 'fix' the missing parts of JavaScript.
• A Superset of JavaScript => JavaScript + Static Types
(and Classes and Modules and more…).
• It uses ES6 syntax with Type Annotation and compiles to
plain JavaScript (target: ES3, ES5, ES6).
• Any valid JavaScript application is also a TypeScript
application
Typescript
tsc app.tsapp.ts app.js
TSC - the TypeScript compiler
TSD - TypeScript Definition Files package manager
TypeScript Definition File (ambient declaration file)
• .d.ts extension.
• Allows the definition of strong types.
• Provide type definition for external JavaScript libraries.
DefinitelyTyped (http://definitelytyped.org/): a community driven project on GitHub that tracks all of them.
Typescript
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter("world");
var button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = function() {
alert(greeter.greet());
}
document.body.appendChild(button);
Type Annotation
Typescript
import {bootstrap, Component} from 'angular2/angular2';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);
Meta Annotation
ES5 Support
(function() {
var AppComponent = ng
.Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
.Class({
constructor: function () { }
});
document.addEventListener('DOMContentLoaded', function() {
ng.bootstrap(AppComponent);
});
})();
Language Support
ES5 ES6 TypeScript Dart
Language Support
CompileNo Compile
ES5 ES6 TypeScript Dart
Language Support
TypesNo Types
ES5 ES6 TypeScript Dart
Language Support
TypeScriptES6 Dart
No JS
TypeScriptES6
JavaScript-Based Syntax
ES5
Browser Support
How Fast?
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Rendering Script Times
Re-rendering Script Times on Changes
Details at bit.ly/1RTFFWG
Tour of Heroes (before Dashboard)
File Structure
angular2-tour-of-heroes
├── node_modules
├── src
| ├── app
| | └── app.ts
| ├── index.html
| └── tsconfig.json
└── package.json
SystemJS Loader : index.js
<html>
<head>
<title>Tour of Heroes</title>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script>
System.config({
packages: {'app': {defaultExtension: 'js'}}
});
System.import('app/app');
</script>
</head>
<body>
<my-app>loading...</my-app>
</body>
</html>
SystemJS Loader
angular2.js bundle (System.register)
Angular2
RxJS
Reflect.js
Zone.js
Application code
SystemJS loader
Define Hero Type - app.ts
class Hero {
id: number;
name: string;
}
Add few heroes - app.ts
var HEROES: Hero[] = [
{ "id": 11, "name": "Mr. Nice" },
{ "id": 12, "name": "Narco" },
{ "id": 13, "name": "Bombasto" },
{ "id": 14, "name": "Celeritas" },
{ "id": 15, "name": "Magneta" },
{ "id": 16, "name": "RubberMan" },
{ "id": 17, "name": "Dynama" },
{ "id": 18, "name": "Dr IQ" },
{ "id": 19, "name": "Magma" },
{ "id": 20, "name": "Tornado" }
];
ES6 Module load - app.ts
import {Component, bootstrap, NgFor} from 'angular2/angular2';
angular.module('app',[ ‘ng’, ‘.....’ ])
angular 1.x
Define AppComponet Using ES6 Class - app.ts
class AppComponent {
public title = 'Tour of Heroes';
public heroes = HEROES;
}
@component
@Component({
selector: 'my-app',
})
class AppComponent {
public title = 'Tour of Heroes';
public heroes = HEROES;
}
@Component({
selector: 'my-app',
template:`
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<template ng-for #hero [ng-for-of]="heroes">
<li><span class="badge">{{hero.id}}</span> {{hero.name}}</li>
</template>
</ul>
`,
directives: [NgFor]
})
class AppComponent {
public title = 'Tour of Heroes';
public heroes = HEROES;
}
template
@Component({
selector: 'my-app',
template:`
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ng-for="#hero of heroes" (click)="onSelect(hero)">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
</ul>
`,
directives: [NgFor]
})
class AppComponent {
public title = 'Tour of Heroes';
public heroes = HEROES;
}
template
Bootstrap
bootstrap(AppComponent);
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Add Encapsulation Style to Component
@Component({
selector: 'my-app',
template:`
...
`,
styles:[`
.heroes {list-style-type: none; margin-left: 1em; padding: 0; width: 10em;}
.heroes li { cursor: pointer; position: relative; left: 0; transition: all 0.2s ease; }
.heroes li:hover {color: #369; background-color: #EEE; left: .2em;}
.heroes .badge {
font-size: small;
color: white;
padding: 0.1em 0.7em;
background-color: #369;
line-height: 1em;
position: relative;
left: -1px;
top: -1px;
}
.selected { background-color: #EEE; color: #369; }
`],
directives: [NgFor]
})
class AppComponent {
public title = 'Tour of Heroes';
public heroes = HEROES;
}
Three way to add style
● Component inline styles
● Styles urls
● Template inline styles
Add Style to Component - Styles urls
@Component({
selector: 'my-app',
template:`
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ng-for="#hero of heroes">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
</ul>
`,
styleUrls : ['app.css'],
directives: [NgFor]
})
class AppComponent {
public title = 'Tour of Heroes';
public heroes = HEROES;
}
Add Style to Component - Template inline styles
@Component({
selector: 'my-app',
template:`
<style>
.heroes {list-style-type: none; margin-left: 1em; padding: 0; width: 10em;}
.heroes li { cursor: pointer; position: relative; left: 0; transition: all 0.2s ease; }
.heroes li:hover {color: #369; background-color: #EEE; left: .2em;}
.heroes .badge {
font-size: small;
color: white;
padding: 0.1em 0.7em;
background-color: #369;
line-height: 1em;
position: relative;
left: -1px;
top: -1px;
}
.selected { background-color: #EEE; color: #369;
</style>
….
`,
directives: [NgFor]
})
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Emulated View Encapsulation
Using Shadow Dom
import {Component, bootstrap, NgFor, ViewEncapsulation} from 'angular2/angular2';
@Component({
selector: 'my-app',
template:`
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ng-for="#hero of heroes" (click)="onSelect(hero)">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
</ul>
`,
styles:[`
….
`],
directives: [NgFor],
encapsulation : ViewEncapsulation.Native
})
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Add event binding
<h1>{{title}}</h1>
<h2>My Heroes</h2>
<ul class="heroes">
<li *ng-for="#hero of heroes" (click)="onSelect(hero)">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
</ul>
class AppComponent {
public title = 'Tour of Heroes';
public heroes = HEROES;
public selectedHero: Hero;
onSelect(hero: Hero) { this.selectedHero = hero; }
}
Two-way Data binding
<div *ng-if="selectedHero">
<h2>{{selectedHero.name}} details!</h2>
<div><label>id: </label>{{selectedHero.id}}</div>
<div>
<label>name: </label>
<input [(ng-model)]="selectedHero.name" placeholder="name"></input>
</div>
</div>
Data Binding in template
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
ng-class
<li *ng-for="#hero of heroes" [ng-class]="getSelectedClass(hero)" (click)="onSelect(hero)">
<span class="badge">{{hero.id}}</span> {{hero.name}}
</li>
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 };
}
}
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
References
- https://angular.io/
- AngularConnect Keynote 2015
- ngVegas The Angular 2 Glossary
- TRY Angular 2
- View Encapsulation in Angular 2
- http://info.meteor.com/blog/comparing-performance-of-blaze-react-angular-
meteor-and-angular-2-with-meteor
Thanks you
QnA

More Related Content

PDF
준비하세요 Angular js 2.0
PDF
[FEConf Korea 2017]Angular 컴포넌트 대화법
PPTX
Angular js
PPTX
The AngularJS way
PPTX
Angular js
PDF
Introduction to AngularJS
PDF
Advanced Tips & Tricks for using Angular JS
PPTX
Angular JS
준비하세요 Angular js 2.0
[FEConf Korea 2017]Angular 컴포넌트 대화법
Angular js
The AngularJS way
Angular js
Introduction to AngularJS
Advanced Tips & Tricks for using Angular JS
Angular JS

What's hot (20)

PDF
AngularJS: an introduction
PDF
AngularJS introduction
PPTX
AngularJS
PDF
AngularJS Basic Training
PDF
AngularJS Project Setup step-by- step guide - RapidValue Solutions
PDF
Modern Web Application Development Workflow - EclipseCon Europe 2014
PDF
Introducing Rendr: Run your Backbone.js apps on the client and server
KEY
AngularJS for designers and developers
PDF
AngularJS Basics with Example
PDF
Workshop 27: Isomorphic web apps with ReactJS
PDF
Nicolas Embleton, Advanced Angular JS
PPTX
Front end development with Angular JS
PDF
AngularJS Basics and Best Practices - CC FE &UX
PPTX
Practical AngularJS
PPTX
AngularJS Internal
PPTX
Understanding angular js
PDF
Workshop 12: AngularJS Parte I
PDF
Javascript Module Patterns
PDF
AngularJS Framework
PDF
Building scalable applications with angular js
AngularJS: an introduction
AngularJS introduction
AngularJS
AngularJS Basic Training
AngularJS Project Setup step-by- step guide - RapidValue Solutions
Modern Web Application Development Workflow - EclipseCon Europe 2014
Introducing Rendr: Run your Backbone.js apps on the client and server
AngularJS for designers and developers
AngularJS Basics with Example
Workshop 27: Isomorphic web apps with ReactJS
Nicolas Embleton, Advanced Angular JS
Front end development with Angular JS
AngularJS Basics and Best Practices - CC FE &UX
Practical AngularJS
AngularJS Internal
Understanding angular js
Workshop 12: AngularJS Parte I
Javascript Module Patterns
AngularJS Framework
Building scalable applications with angular js
Ad

Viewers also liked (20)

PPTX
Angular 2 어디까지 왔을까
PPTX
Angular2를 활용한 컴포넌트 중심의 개발
PPTX
Angular2 가기전 Type script소개
PDF
Angularjs 도입 선택 가이드
PDF
AngularJS 2, version 1 and ReactJS
PDF
Front end dev 2016 & beyond
PPTX
Angular2를 위한 컴포넌트 분석과 개발
PPTX
기술용어 선호도 조사 결과
PDF
현실적 PWA
PPTX
Angular2를 위한 타입스크립트
PDF
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
PPTX
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민
PPTX
Angular js 2.0 preview
PDF
진보한 개발 환경에서 품질 좋은 코드 생산 (WebStorm)
PPTX
Angular 1 + es6
PPTX
Angular2 NgModule
PDF
JavaScript 프레임워크 살펴보기
PPTX
Test-Driven JavaScript Development (JavaZone 2010)
KEY
Agile JavaScript Testing
PDF
Efficient JavaScript Unit Testing, May 2012
Angular 2 어디까지 왔을까
Angular2를 활용한 컴포넌트 중심의 개발
Angular2 가기전 Type script소개
Angularjs 도입 선택 가이드
AngularJS 2, version 1 and ReactJS
Front end dev 2016 & beyond
Angular2를 위한 컴포넌트 분석과 개발
기술용어 선호도 조사 결과
현실적 PWA
Angular2를 위한 타입스크립트
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민
Angular js 2.0 preview
진보한 개발 환경에서 품질 좋은 코드 생산 (WebStorm)
Angular 1 + es6
Angular2 NgModule
JavaScript 프레임워크 살펴보기
Test-Driven JavaScript Development (JavaZone 2010)
Agile JavaScript Testing
Efficient JavaScript Unit Testing, May 2012
Ad

Similar to Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점 (20)

PPTX
Angular 2 KTS
PDF
Commit University - Exploring Angular 2
PDF
An introduction to Angular2
PDF
Angular 2 - The Next Framework
PDF
Angular 2 Essential Training
PPTX
Peggy angular 2 in meteor
PPTX
Angular2 + rxjs
PDF
Angular 2 introduction
PDF
Angular2 with type script
PPTX
Foster - Getting started with Angular
PDF
Exploring Angular 2 - Episode 1
PPTX
Angular2 for Beginners
PPTX
An afternoon with angular 2
PPTX
An evening with Angular 2
PDF
Building Blocks of Angular 2 and ASP.NET Core
PPTX
Fly High With Angular - How to build an app using Angular
PDF
Basic overview of Angular
PDF
Angular 2 overview in 60 minutes
PPTX
Introduction to Angular2
PPTX
Angular2 and You
Angular 2 KTS
Commit University - Exploring Angular 2
An introduction to Angular2
Angular 2 - The Next Framework
Angular 2 Essential Training
Peggy angular 2 in meteor
Angular2 + rxjs
Angular 2 introduction
Angular2 with type script
Foster - Getting started with Angular
Exploring Angular 2 - Episode 1
Angular2 for Beginners
An afternoon with angular 2
An evening with Angular 2
Building Blocks of Angular 2 and ASP.NET Core
Fly High With Angular - How to build an app using Angular
Basic overview of Angular
Angular 2 overview in 60 minutes
Introduction to Angular2
Angular2 and You

Recently uploaded (20)

PPTX
"Secure File Sharing Solutions on AWS".pptx
PDF
Cost to Outsource Software Development in 2025
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Introduction to Windows Operating System
PDF
DNT Brochure 2025 – ISV Solutions @ D365
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
assetexplorer- product-overview - presentation
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
STL Containers in C++ : Sequence Container : Vector
PPTX
Tech Workshop Escape Room Tech Workshop
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Time Tracking Features That Teams and Organizations Actually Need
"Secure File Sharing Solutions on AWS".pptx
Cost to Outsource Software Development in 2025
Computer Software and OS of computer science of grade 11.pptx
Advanced SystemCare Ultimate Crack + Portable (2025)
Digital Systems & Binary Numbers (comprehensive )
Introduction to Windows Operating System
DNT Brochure 2025 – ISV Solutions @ D365
How to Use SharePoint as an ISO-Compliant Document Management System
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
assetexplorer- product-overview - presentation
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
STL Containers in C++ : Sequence Container : Vector
Tech Workshop Escape Room Tech Workshop
Trending Python Topics for Data Visualization in 2025
iTop VPN Crack Latest Version Full Key 2025
Wondershare Recoverit Full Crack New Version (Latest 2025)
Salesforce Agentforce AI Implementation.pdf
Complete Guide to Website Development in Malaysia for SMEs
Time Tracking Features That Teams and Organizations Actually Need

Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점

  • 1. Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점 고재도 W3C HTML5 Conference 2015
  • 2. +jeado.ko haibane84@gmail.com - “Bitfinder.co” Software Engineer - “kt” IoT Platform Researcher - “http://webframeworks.kr” AngularJS Tutorial Contributor - “Google Developer Group Korea WebTech” Organizer - “시작하세요 AngularJS wikibooks” Author
  • 3. Change of Web Frontend Library Feature-Complete Framework MVC Framework Component
  • 10. Component = Building block (LEGO) = a group of HTML elements
  • 11. Component is made of two main parts - View - Logic
  • 12. Components View <section> <h4>{{ profile.name }}</h4> <p> Age - {{ profile.age }}</p> <button ng-click="save()">Save</button> </section> <profile-card profile="profile"></profile-card> Reusable group of element
  • 13. Component Logic A Object/Function - A place to store properties and functions function ProfileCardCtrl(){ this.profile = new Profile({ name : 'jay' }); this.save = function(){ // ... } }
  • 14. So How ? React Component class HeloMessage extends React.Component { render() { return <div>Hello {this.props.name}</div>; } } React.render(<HelloMessage name="Jay" />, mountNode); Ember Component App.AppProfileComponent = Ember.Component.extend({ actions: { hello: function(name) { console.log("Hello", name); } } }); <!-- app-profile template --> <h1>{{person.title}}</h1> <img src={{person.avatar}}> <p class='signature'>{{person.signature}}</p> {{app-profile person=currentUser}} Polymer Component //////// porot-element.html //////// <link rel="import" href="bower_components/polymer/polymer.html"> <script> Polymer({ is: "proto-element", ready: function() { this.textContent = "I'm a proto-element." } }); </script> //////// index.html //////// </head> <link rel="import" href="proto-element.html"> </head> <body> <proto-element></proto-element> </body>
  • 15. Angular Connect, London, October 2015 Angular 2.0
  • 16. Angular Connect, London, October 2015 2.0.0-alpha.48 (2015-12-05)
  • 17. My First Component import {bootstrap, Component} from 'angular2/angular2'; @Component({ selector: 'my-app', template: '<h1>My First Angular 2 App</h1>' }) class AppComponent { } bootstrap(AppComponent); //index.html <my-app>loading...</my-app>
  • 19. Typescript • Open Source project from Microsoft Technologies. • An attempt to 'fix' the missing parts of JavaScript. • A Superset of JavaScript => JavaScript + Static Types (and Classes and Modules and more…). • It uses ES6 syntax with Type Annotation and compiles to plain JavaScript (target: ES3, ES5, ES6). • Any valid JavaScript application is also a TypeScript application
  • 20. Typescript tsc app.tsapp.ts app.js TSC - the TypeScript compiler TSD - TypeScript Definition Files package manager TypeScript Definition File (ambient declaration file) • .d.ts extension. • Allows the definition of strong types. • Provide type definition for external JavaScript libraries. DefinitelyTyped (http://definitelytyped.org/): a community driven project on GitHub that tracks all of them.
  • 21. Typescript class Greeter { greeting: string; constructor(message: string) { this.greeting = message; } greet() { return "Hello, " + this.greeting; } } var greeter = new Greeter("world"); var button = document.createElement('button'); button.textContent = "Say Hello"; button.onclick = function() { alert(greeter.greet()); } document.body.appendChild(button); Type Annotation
  • 22. Typescript import {bootstrap, Component} from 'angular2/angular2'; @Component({ selector: 'my-app', template: '<h1>My First Angular 2 App</h1>' }) class AppComponent { } bootstrap(AppComponent); Meta Annotation
  • 24. (function() { var AppComponent = ng .Component({ selector: 'my-app', template: '<h1>My First Angular 2 App</h1>' }) .Class({ constructor: function () { } }); document.addEventListener('DOMContentLoaded', function() { ng.bootstrap(AppComponent); }); })();
  • 25. Language Support ES5 ES6 TypeScript Dart
  • 27. Language Support TypesNo Types ES5 ES6 TypeScript Dart
  • 28. Language Support TypeScriptES6 Dart No JS TypeScriptES6 JavaScript-Based Syntax ES5
  • 35. Tour of Heroes (before Dashboard)
  • 36. File Structure angular2-tour-of-heroes ├── node_modules ├── src | ├── app | | └── app.ts | ├── index.html | └── tsconfig.json └── package.json
  • 37. SystemJS Loader : index.js <html> <head> <title>Tour of Heroes</title> <script src="../node_modules/systemjs/dist/system.src.js"></script> <script src="../node_modules/angular2/bundles/angular2.dev.js"></script> <script> System.config({ packages: {'app': {defaultExtension: 'js'}} }); System.import('app/app'); </script> </head> <body> <my-app>loading...</my-app> </body> </html>
  • 38. SystemJS Loader angular2.js bundle (System.register) Angular2 RxJS Reflect.js Zone.js Application code SystemJS loader
  • 39. Define Hero Type - app.ts class Hero { id: number; name: string; }
  • 40. Add few heroes - app.ts var HEROES: Hero[] = [ { "id": 11, "name": "Mr. Nice" }, { "id": 12, "name": "Narco" }, { "id": 13, "name": "Bombasto" }, { "id": 14, "name": "Celeritas" }, { "id": 15, "name": "Magneta" }, { "id": 16, "name": "RubberMan" }, { "id": 17, "name": "Dynama" }, { "id": 18, "name": "Dr IQ" }, { "id": 19, "name": "Magma" }, { "id": 20, "name": "Tornado" } ];
  • 41. ES6 Module load - app.ts import {Component, bootstrap, NgFor} from 'angular2/angular2'; angular.module('app',[ ‘ng’, ‘.....’ ]) angular 1.x
  • 42. Define AppComponet Using ES6 Class - app.ts class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; }
  • 43. @component @Component({ selector: 'my-app', }) class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; }
  • 44. @Component({ selector: 'my-app', template:` <h1>{{title}}</h1> <h2>My Heroes</h2> <ul class="heroes"> <template ng-for #hero [ng-for-of]="heroes"> <li><span class="badge">{{hero.id}}</span> {{hero.name}}</li> </template> </ul> `, directives: [NgFor] }) class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; } template
  • 45. @Component({ selector: 'my-app', template:` <h1>{{title}}</h1> <h2>My Heroes</h2> <ul class="heroes"> <li *ng-for="#hero of heroes" (click)="onSelect(hero)"> <span class="badge">{{hero.id}}</span> {{hero.name}} </li> </ul> `, directives: [NgFor] }) class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; } template
  • 48. Add Encapsulation Style to Component @Component({ selector: 'my-app', template:` ... `, styles:[` .heroes {list-style-type: none; margin-left: 1em; padding: 0; width: 10em;} .heroes li { cursor: pointer; position: relative; left: 0; transition: all 0.2s ease; } .heroes li:hover {color: #369; background-color: #EEE; left: .2em;} .heroes .badge { font-size: small; color: white; padding: 0.1em 0.7em; background-color: #369; line-height: 1em; position: relative; left: -1px; top: -1px; } .selected { background-color: #EEE; color: #369; } `], directives: [NgFor] }) class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; }
  • 49. Three way to add style ● Component inline styles ● Styles urls ● Template inline styles
  • 50. Add Style to Component - Styles urls @Component({ selector: 'my-app', template:` <h1>{{title}}</h1> <h2>My Heroes</h2> <ul class="heroes"> <li *ng-for="#hero of heroes"> <span class="badge">{{hero.id}}</span> {{hero.name}} </li> </ul> `, styleUrls : ['app.css'], directives: [NgFor] }) class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; }
  • 51. Add Style to Component - Template inline styles @Component({ selector: 'my-app', template:` <style> .heroes {list-style-type: none; margin-left: 1em; padding: 0; width: 10em;} .heroes li { cursor: pointer; position: relative; left: 0; transition: all 0.2s ease; } .heroes li:hover {color: #369; background-color: #EEE; left: .2em;} .heroes .badge { font-size: small; color: white; padding: 0.1em 0.7em; background-color: #369; line-height: 1em; position: relative; left: -1px; top: -1px; } .selected { background-color: #EEE; color: #369; </style> …. `, directives: [NgFor] })
  • 54. Using Shadow Dom import {Component, bootstrap, NgFor, ViewEncapsulation} from 'angular2/angular2'; @Component({ selector: 'my-app', template:` <h1>{{title}}</h1> <h2>My Heroes</h2> <ul class="heroes"> <li *ng-for="#hero of heroes" (click)="onSelect(hero)"> <span class="badge">{{hero.id}}</span> {{hero.name}} </li> </ul> `, styles:[` …. `], directives: [NgFor], encapsulation : ViewEncapsulation.Native })
  • 56. Add event binding <h1>{{title}}</h1> <h2>My Heroes</h2> <ul class="heroes"> <li *ng-for="#hero of heroes" (click)="onSelect(hero)"> <span class="badge">{{hero.id}}</span> {{hero.name}} </li> </ul> class AppComponent { public title = 'Tour of Heroes'; public heroes = HEROES; public selectedHero: Hero; onSelect(hero: Hero) { this.selectedHero = hero; } }
  • 57. Two-way Data binding <div *ng-if="selectedHero"> <h2>{{selectedHero.name}} details!</h2> <div><label>id: </label>{{selectedHero.id}}</div> <div> <label>name: </label> <input [(ng-model)]="selectedHero.name" placeholder="name"></input> </div> </div>
  • 58. Data Binding in template
  • 60. ng-class <li *ng-for="#hero of heroes" [ng-class]="getSelectedClass(hero)" (click)="onSelect(hero)"> <span class="badge">{{hero.id}}</span> {{hero.name}} </li> 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 }; } }
  • 63. References - https://angular.io/ - AngularConnect Keynote 2015 - ngVegas The Angular 2 Glossary - TRY Angular 2 - View Encapsulation in Angular 2 - http://info.meteor.com/blog/comparing-performance-of-blaze-react-angular- meteor-and-angular-2-with-meteor