SlideShare a Scribd company logo
Angular 2
@EmmanuelDemey
Emmanuel
DEMEY
Consultant & Formateur Web
Zenika Nord
@EmmanuelDemey
Web / Domotique / Histoire / Biérologie
Technozaure - Angular2
Les choses que nous n'aimons pas...
Architecture AngularJS
MV* MV* MV*
Architecture AngularJS
MV* MV* MV*
Architecture AngularJS
DI (provider, service, factory...)
MV* MV* MV*
Architecture AngularJS
DI (provider, service, factory...)
MV* MV* MV*
Filtres
Architecture AngularJS
DI (provider, service, factory...)
MV* MV* MV*
Filtres
API des Directives
app.directive('MyDirective', function(){
return {
restrict: 'AE',
require: '?^^ngModel',
scope: { variable: '@' },
compile: function(...) {
return {
pre: function(...) { ... },
post: function(...) { ... }
}
},
link: function(...) { ... }
}
});
app.directive('MyDirective', function(){
return {
restrict: 'AE',
require: '?^^ngModel',
scope: { variable: '@' },
compile: function(...) {
return {
pre: function(...) { ... },
post: function(...) { ... }
}
},
link: function(...) { ... }
}
});
API des Directives
app.directive('MyDirective', function(){
return {
restrict: 'AE',
require: '?^^ngModel',
scope: { variable: '@' },
compile: function(...) {
return {
pre: function(...) { ... },
post: function(...) { ... }
}
},
link: function(...) { ... }
}
});
API des Directives
app.directive('MyDirective', function(){
return {
restrict: 'AE',
require: '?^^ngModel',
scope: { variable: '@' },
compile: function(...) {
return {
pre: function(...) { ... },
post: function(...) { ... }
}
},
link: function(...) { ... }
}
});
API des Directives
<input ng-model="firstName">
<p>
{{firstName }}
</p>
2-way data-binding
<input ng-model="firstName"
ng-model-options="options">
<p>
{{firstName }}
</p>
2-way data-binding
<input ng-model="firstName">
<p>
{{::firstName }}
</p>
2-way data-binding
Et ce n'est pas fini...
Mais aussi...
Pas de Server-Side Rendering
Gestion des événements (ngClick, ...)
Gestion des attributs HTML (ngSrc, ...)
La solution... Angular 2
Attention !
Version Alpha
P(eu|as) de Doc
Architecture
Composants
Injection de Dépendance
Pipes
Architecture Angular 2
<app></app>
Architecture Angular 2
<app></app>
menu grid
gallery
Architecture Angular 2
<app></app>
menu grid
gallery
DI
(classes ES6 ou TypeScript)
Pipes
(classes ES6 ou TypeScript)
La Famille JavaScript
La Famille JavaScript
ES5
La Famille JavaScript
ES5
ES2015
La Famille JavaScript
ES5
ES2015
La Famille JavaScript
ES5
ES2015
TypeScript
Les Web Components
Custom Elements Templates Imports Shadow DOM
Composants Angular 2
Ressources de base en Angular 2
Tout est composant
Application représentée par un arbre
de composants
Utilisation de métadonnées pour
configurer un composant
//<my-app></my-app>
function MyAppComponent() {
}
MyAppComponent.annotations = [
new angular.ComponentAnnotation({
selector: 'my-app'
}),
new angular.ViewAnnotation({
template: "<main>" +
"<h1> This is my first Angular2 app</h1>" +
"</main>"
})
];
Composant version ES5
import {Component, View} from 'angular2/angular2';
@Component({selector: 'my-app'})
@View({
template: `<main>
<h1> This is my first Angular2 app</h1>
</main>`
})
class MyAppComponent {
}
Composant version TypeScript
import {Component, View,
bootstrap} from 'angular2/angular2';
@Component({selector: 'my-app'})
@View({
template: `<main>
<h1> This is my first Angular2 app</h1>
</main>`
})
class MyAppComponent {
}
bootstrap(MyAppComponent);
Bootstrap de l'Application
Binding
Root Cpt
Child1 Cpt Child2 Cpt
[property]="expression"
(event)="update()"
Property Binding
<input [attr]="expression" />
Accès à toutes les propriétés des éléments
HTML
Possibilité de définir de nouvelles propriétés
Compatibilité avec d'autres spécifications
Property Binding
<body>
<h1>My First Angular2 app</h1>
</body>
Property Binding
<body>
<h1 [textContent]="'My First Angular2 app'">
</h1>
</body>
Property Binding
<body>
<h1>{{'My First Angular2 app'}}
</h1>
</body>
Property Binding
//<beerItem [beer]="'Maredsous'"></beerItem>
@Component({
selector: 'beerItem',
properties: ['beer']
})
@View({
template: `<section>
<h2>{{beer}}</h2>
<button>Je veux celle-ci !</button>
</section>`
})
class BeerItem{
beer: String;
}
Event Binding
<input (event)="expression" />
Accès à tous les événements des éléments
HTML
Possibilité de définir de nouveaux événements
Event Bindings
//<beerItem [beer]="'Maredsous'" (selectBeer)="sendToBeerTap()"></beerItem>
@Component({
selector: 'beerItem',
properties: ['beer'],
events: ['selectBeer']
})
@View({
template: `<section>
<h2>{{beer}}</h2>
<button (click)="selectItem()">Je veux celle-ci !</button>
</section>`
})
class BeerItem {
beer: String;
selectBeer: EventEmitter;
selectItem() {
this.selectBeer.next(this.beer);
}
}
Syntaxe valide ?
“Attribute names must consist of one or
more characters other than the space
characters, U+0000 NULL, """, "'", ">", "/",
"=", the control characters, and any
characters that are not defined by Unicode.
Syntaxe valide ?
Syntaxe valide ?
Component Dependency
Nécessité d'importer les composants
nécessaires à votre application
Propriété directives de @View
Component Dependency
import {Component, View, bootstrap, NgFor} from 'angular2/angular2';
import {BeerItem} from 'BeerItem';
@Component({ selector: 'my-app'})
@View({
template: `<main class="mdl-layout__content">
<ul class="googleapp-card-list">
<li *ng-for="#beer of beers">
<beerItem [beer]="beer"></beerItem>
</li>
</ul>
</main>`,
directives: [NgFor, BeerItem]
})
class MyAppComponent {
public beers: String[] = [];
constructor() { }
}
Injection de Dépendances
Code métier dans des services
Chaque Service est un singleton
Principe d'Hollywood
Multiples implémentations en NG1 !
Injection de Dépendances
app.service('TapService', function($http){
this.getBeer = function(beerId){
return $http.get('/api/i-am-thirsty/' + beerId);
};
});
app.controller('AppCtrl', function(TapService){
this.selectBeer = function(idBeer){
return TapService.getBeer(idBeer);
}
});
DI version Angular2
1 Injecteur principal + 1 Injecteur par composant
Hérite de l'injecteur parent
Possibilité de redéfinir le Service à injecter
Utilisation d'annotations en ES6 et des types en
TypeScript
Services disponibles via le constructeur du
composant
Injecteur Principal - toValue
@Component({selector: 'my-app'})
@View({
template: `<main>
<h1> Welcome to our {{breweryName}}</h1>
</main>`
})
class MyAppComponent {
constructeur(public breweryName:String){
}
}
bootstrap(MyAppComponent, [bind(String).toValue('Zenika Brewery')]);
Injecteur Principal - toClass
@Component({selector: 'my-app'})
@View({
template: `<main>
<h1> Welcome to our {{breweryName}}</h1>
</main>`
})
class MyAppComponent {
constructeur(private breweryService:BreweryService){
this.breweryName = this.breweryService.getBreweryName();
}
}
bootstrap(MyAppComponent, [bind(BreweryService).toClass(BreweryService)]);
Injecteur Principal - toClass
@Component({selector: 'my-app'})
@View({
template: `<main>
<h1> Welcome to our {{breweryName}}</h1>
</main>`
})
class MyAppComponent {
constructeur(private breweryService:BreweryService){
this.breweryName = this.breweryService.getBreweryName();
}
}
bootstrap(MyAppComponent, [BreweryService]);
Injecteur Principal -
toFactory@Component({selector: 'my-app'})
@View({
template: `<main>
<h1> Welcome to our {{breweryName}}</h1>
</main>`
})
class MyAppComponent {
constructeur(public breweryName:String){ }
}
bootstrap(MyAppComponent,
[bind(String)
.toFactory((BreweryService) => {
return BreweryService.getBreweryName();
}, [BreweryService])]);
Child Injector
@Component({selector: 'my-app'})
@View({
template: `<main>
<welcome-message></welcome-message>
</main>`,
directives: [WelcomeMessage]
})
class MyAppComponent {
constructeur(public breweryName:String){ }
}
bootstrap(MyAppComponent, [bind(String).toValue('Zenika Brewery')]);
Child Injector
@Component({
selector: 'welcome-message'
})
@View({
template: `<h1>Welcome to our {{breweryName}}</h1>`
})
class WelcomeMessage{
constructeur(public breweryName:String){
}
}
Child Injector
@Component({
selector: 'welcome-message'
})
@View({
template: `<h1>Welcome to our {{breweryName}}</h1>`,
bindings: [
bind(String).toValue('Awesome Zenika Brewery')
]
})
class WelcomeMessage{
constructeur(public breweryName:String){
}
}
Pipes
Identiques aux filtres d'AngularJS 1
Permet de manipuler une donnée
Utilisation d'une classe annotée @Pipe
Pipes disponibles dans le framework :
upperCase, lowerCase, Async,
Number, limitTo, json et date
Pipes
import {Pipe} from 'angular2/angular2';
@Pipe({
name: 'UpperCasePipe'
})
export class UpperCasePipe implements PipeTransform {
transform(value: String, args: any[]) {
return value.toUpperCase();
}
}
Pipes
import {Component, View} from 'angular2/angular2';
import {UpperCasePipe} from './UpperCasePipe.ts'
@Component({
selector: 'comp'
})
@View({
template: `<div>{{'Démo utilisant les pipes' | UpperCasePipe}}</div>`,
pipes: [UpperCasePipe]
})
export class Component{}
Pipes
import {Component, View} from 'angular2/angular2';
import {UpperCasePipe} from './UpperCasePipe.ts'
@Component({
selector: 'comp'
})
@View({
template: ``,
bindings: [UpperCasePipe]
})
export class Component{
constructor(public upperCasePipe:UpperCasePipe){
this.upperCasePipe.transform('Un autre exemple...');
}
}
@Component
@View@Directive
@View
@Animation
@Inject
@InjectLazy
@Optional
@Host
@Parent
@Pipe
@Property
@Event
@RouteConfig
@HostBinding
@HostEvent
@ContentChild
@ContentChildren
@ViewChildren
Roadmap
Repository Github
Documentation
http://blog.thoughtram.io/
NG Europe 2014
NG Conf 2015
AngularU
ESLint Plugin Angular
John Papa Styleguide
Questions ?
Technozaure - Angular2

More Related Content

What's hot (19)

PDF
Commit University - Exploring Angular 2
Commit University
 
ODP
Angular js-crash-course
Keith Bloomfield
 
PDF
Sharper Better Faster Dagger ‡ - Droidcon SF
Pierre-Yves Ricau
 
PDF
Angular server side rendering - Strategies & Technics
Eliran Eliassy
 
PDF
Styling recipes for Angular components
Nir Kaufman
 
PDF
Angular 2 - The Next Framework
Commit University
 
PDF
Ngrx meta reducers
Eliran Eliassy
 
PDF
ParisJS #10 : RequireJS
Julien Cabanès
 
PDF
Solid angular
Nir Kaufman
 
PPTX
Angular 2.0 Dependency injection
Eyal Vardi
 
ODP
AngularJs Crash Course
Keith Bloomfield
 
PDF
An introduction to Angular2
Apptension
 
PDF
Explaination of angular
Kan-Han (John) Lu
 
PDF
Angular 2: core concepts
Codemotion
 
PPTX
Peggy angular 2 in meteor
LearningTech
 
PPT
Angular 8
Sunil OS
 
PDF
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
PDF
AngularJS - TechTalk 3/2/2014
Spyros Ioakeimidis
 
PDF
A gently introduction to AngularJS
Gregor Woiwode
 
Commit University - Exploring Angular 2
Commit University
 
Angular js-crash-course
Keith Bloomfield
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Pierre-Yves Ricau
 
Angular server side rendering - Strategies & Technics
Eliran Eliassy
 
Styling recipes for Angular components
Nir Kaufman
 
Angular 2 - The Next Framework
Commit University
 
Ngrx meta reducers
Eliran Eliassy
 
ParisJS #10 : RequireJS
Julien Cabanès
 
Solid angular
Nir Kaufman
 
Angular 2.0 Dependency injection
Eyal Vardi
 
AngularJs Crash Course
Keith Bloomfield
 
An introduction to Angular2
Apptension
 
Explaination of angular
Kan-Han (John) Lu
 
Angular 2: core concepts
Codemotion
 
Peggy angular 2 in meteor
LearningTech
 
Angular 8
Sunil OS
 
AngularJS Project Setup step-by- step guide - RapidValue Solutions
RapidValue
 
AngularJS - TechTalk 3/2/2014
Spyros Ioakeimidis
 
A gently introduction to AngularJS
Gregor Woiwode
 

Similar to Technozaure - Angular2 (20)

PDF
ChtiJUG - Introduction à Angular2
Demey Emmanuel
 
PDF
angular fundamentals.pdf angular fundamentals.pdf
NuttavutThongjor1
 
PPTX
Introduction to Angular2
Ivan Matiishyn
 
PDF
XebiConFr 15 - Brace yourselves Angular 2 is coming
Publicis Sapient Engineering
 
PDF
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Ontico
 
PDF
angular fundamentals.pdf
NuttavutThongjor1
 
PDF
Workshop 13: AngularJS Parte II
Visual Engineering
 
PDF
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
PPTX
Building a TV show with Angular, Bootstrap, and Web Services
David Giard
 
PDF
Angular 2.0 - What to expect
Allan Marques Baptista
 
PPTX
Angular1x and Angular 2 for Beginners
Oswald Campesato
 
PDF
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
Wim Selles
 
PPTX
mean stack
michaelaaron25322
 
PPTX
AngularJs-training
Pratchaya Suputsopon
 
PPTX
Angular 2 - a New Hope
Sami Suo-Heikki
 
PDF
AngularJS - Services
Nir Kaufman
 
PPTX
Angular 2 Migration - JHipster Meetup 6
William Marques
 
PPTX
Angular js
Behind D Walls
 
PDF
Opinionated AngularJS
prabhutech
 
PPTX
AngularJS $Provide Service
Eyal Vardi
 
ChtiJUG - Introduction à Angular2
Demey Emmanuel
 
angular fundamentals.pdf angular fundamentals.pdf
NuttavutThongjor1
 
Introduction to Angular2
Ivan Matiishyn
 
XebiConFr 15 - Brace yourselves Angular 2 is coming
Publicis Sapient Engineering
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Ontico
 
angular fundamentals.pdf
NuttavutThongjor1
 
Workshop 13: AngularJS Parte II
Visual Engineering
 
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
Building a TV show with Angular, Bootstrap, and Web Services
David Giard
 
Angular 2.0 - What to expect
Allan Marques Baptista
 
Angular1x and Angular 2 for Beginners
Oswald Campesato
 
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
Wim Selles
 
mean stack
michaelaaron25322
 
AngularJs-training
Pratchaya Suputsopon
 
Angular 2 - a New Hope
Sami Suo-Heikki
 
AngularJS - Services
Nir Kaufman
 
Angular 2 Migration - JHipster Meetup 6
William Marques
 
Angular js
Behind D Walls
 
Opinionated AngularJS
prabhutech
 
AngularJS $Provide Service
Eyal Vardi
 
Ad

Recently uploaded (20)

PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Digital Circuits, important subject in CS
contactparinay1
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Ad

Technozaure - Angular2