SlideShare a Scribd company logo
Angular 2
IN ACTION
NG2 INTRODUCTION
Part 2
Angular2  - In Action
TSD
TSD
npm install tsd -g
tsd install angular2/angular2 angular2/router rx es6-promise
TSC
tsc app.ts --target ES5
--module system --experimentalDecorators
--moduleResolution node
--emitDecoratorMetadata
--outFile app.js
Start
HTML
<!doctype html>
<html lang="en">
<body>
<my-app></my-app>
<script src="js/bundle.js"></script>
</body>
</html>
APP.TS - IMPORTS
/// <reference path="../../typings/tsd.d.ts" />
import {
Component,
View,
bootstrap,
CORE_DIRECTIVES,
FORM_DIRECTIVES,
provide
} from 'angular2/angular2';
//...
APP.TS - COMPONENT
@Component({
selector: 'my-app',
template: APP_TEMPLATE,
directives: [HeaderComponent,
ROUTER_DIRECTIVES],
provides: [PostsStorage, Core]
})
class AppComponent {}
APP.TS - BOOTSTRAP
bootstrap(AppComponent, [
// Common
PostsStorage,
Core,
// Ng2
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(APP_BASE_HREF, {useValue: '/'})
]);
Templates
TEMPLATES - IMPORT
import {
APP_TEMPLATE
} from './templates';
TEMPLATES - EXAMPLE COMPONENT
class AppComponent {
text:string = 'hello';
typing($event){
this.text = $event.target.value;
}
}
TEMPLATES - CODE
<h1>Bound Textbox</h1>
<input
[value]="text"
(keyup)="typing($event)" />
{{text}}
TEMPLATES - SYNTAX
<todo-cmp [model]="my_value"></todo-cmp>
<input
[ng-model]="todo.text"
(ng-model-change)="todo.text=$event"
></input>
<input [(ng-model)]="todo.text"></input>
TEMPLATES - SYNTAX
<video-player #player></video-player>
<button (click)="player.pause()">
Pause
</button>
<input #i>
{{i.value}}
PIPE
PIPE - USAGE
@Pipe({
name: 'publicName'
})
class ClassPipeName implements PipeTransform {
transform(value: number, args: any[]) {
//…
}
}
PIPE - USAGE
@Pipe({
name: 'publicName'
})
class ClassPipeName implements PipeTransform {
transform(value: number, args: any[]) {
//…
}
}
Routing
ROUTING - @RouteConfig
import {
AboutComponent
} from './components/about/index';
@RouteConfig([{
path: '/About/:id',
component: AboutComponent,
name: 'About'
}])
class AppComponent {}
ROUTING - @RouteConfig
export class AboutComponent {
id: number;
constructor( @Inject(RouteParams) params: RouteParams) {
this.id = params.get('id');
}
}
ROUTING - TEMPLATE
<nav>
<ul>
<a [router-link]="['./About', {id: 1}]" href="#"
class="list-group-item">About</a>
<a [router-link]="['./Home']" href="#" class="list-group-
item">Home</a>
<a [router-link]="['./PostsList']" href="#" class="list-
group-item">Posts list</a>
</ul>
</nav>
<route-transclusion name="main"></route-transclusion>
LINKS
react / angular / angular2
ng-conf
● https://github.com/htdt/ng2-jspm
● https://github.com/thelgevold/angular-2-samples
● http://www.syntaxsuccess.com/angular-2-articles
●
BUILDING / COMPILE /
TRANSCRIPTION
Part 2
Browserify
ROUTING - TEMPLATE
var browserify = require('gulp-browserify');
gulp.src('build/ts/app/app.js')
.pipe(browserify({
insertGlobals : true,
debug : !gulp.env.production
}))
.pipe(gulp.dest('./dist/app'))
NO
JSPM
JSMP
“jspm is a package manager for the SystemJS universal module
loader, built on top of the dynamic ES6 module loader”
React applications with JSPM
JSMP
● ES6, AMD, CommonJS and globals)
● npm and GitHub...
● load modules as separate files
● optimize into a bundle
● realtime transcript
System.js
SYSTEM.JS - PRODUCTION
npm install -g jspm
jspm init
jspm install angular2/angular2
jspm bundle-sfx --minify zone.js + whatwg-fetch + reflect-metadata
+ src/app/app dist/js/bundle.js
SYSTEM.JS - DEVELOPMENT
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.import('reflect-metadata')
.then(function(){System.import('zone.js')})
// .then(function(){System.import('es5-shim')}) <- LOL
.then(function(){System.import('es6-shim')})
.then(function(){System.import('whatwg-fetch')})
.then(function(){System.import('src/app/app')});
</script>
SYSTEM.JS - PRODUCTION
<!doctype html>
<html lang="en">
<body>
<my-app></my-app>
<script src="js/bundle.js"></script>
</body>
</html>
Gulp
GULP - TEMPLATES
var ng2Template = "export const <%= template.url %> = '<%=
template.escapedContent %>';n";
function fnRename(templateUrl, templateFile) {
var pathParts = templateUrl.replace('.tpl.html', '').split('/'),
folder = pathParts[pathParts.length - 2],
file = pathParts[pathParts.length - 1],
name = (folder ? folder + '_' : '') + file + '_TEMPLATE';
return name.toUpperCase().replace(/-[.-]/g,
function (match) {
return '_';
});
}
}
/*...*/.pipe(ngHtml2Js({
rename: fnRename,
template: ng2Template
})
PRERENDER
Part 3
Metadata
Metadata - HTML
<!doctype html>
<html lang="en">
<head>
<title>{{ no.work.here }}</title>
<head>
<body>
<my-app></my-app>
<script src="js/bundle.js"></script>
</body>
</html>
METADATA - SERVICE
export class HeadDOM {
private titleDom:HTMLElement;
get title():string {
return this.titleDom.innerText;
}
set title(title:string) {
this.titleDom.innerText = title;
this.ogTitle = title;
}
//…
}
Prerender.io
PRERENDER.IO - COST
PRERENDER.IO - GITHUB
https://github.com/prerender/prerender
Webrender-service
Webrender-service - Overview
● (+) Render png file
● (+) Render pdf file
● (+) Render html file
● (+) No-overwrite js functions
● (+) Servers whitelist
● (+) Token security
● (-) Legacy code
● (-) Small community
● (-) No-good tested
● (-) Use node-babel
● (-) Alpha
Webrender-service - Todo
● Remove babel (problems with debugging)
● Write unit tests
● Remove cache (I recommend to use solution like varnish)
WEBRENDER SERVICE (ALPHA) - GITHUB
https://bitbucket.org/spozoga/webrender-service
PhantomJS
PhantomJS - Error #1
Map is a pretty new structure. Use npm install harmony-collections --
save-dev and add "node_modules/harmony-collections/harmony-
collections.min.js", to the karma config.
PhantomJS - Error #2
ORIGINAL EXCEPTION: TypeError: 'undefined' is not a function
(evaluating 'window.requestAnimationFrame(callback)')
PhantomJS - Error #3
RangeError: Maximum call stack size exceeded.
at quote
(/Users/spozoga/dev/prerender/node_modules/phantom/shim.js:
1065)
………..
DevOps
VARNISH
PRERENDER.IO - GITHUB
https://github.com/prerender/prerender
PRERENDER-VARNISH - GITHUB
https://github.com/MWers/prerender-varnish
The end
Sebastian Pożoga
sebastian@pozoga.eu

More Related Content

PDF
Angular2 workshop
PDF
Data Flow Patterns in Angular 2 - Sebastian Müller
PPTX
Angular js 2
PPT
Elefrant [ng-Poznan]
PDF
An introduction to Angular2
PDF
Angular Dependency Injection
PDF
The productive developer guide to Angular 2
PDF
Angular 2: core concepts
Angular2 workshop
Data Flow Patterns in Angular 2 - Sebastian Müller
Angular js 2
Elefrant [ng-Poznan]
An introduction to Angular2
Angular Dependency Injection
The productive developer guide to Angular 2
Angular 2: core concepts

What's hot (20)

PPTX
AngularJS2 / TypeScript / CLI
PPTX
Angular2 + rxjs
PDF
Angular2 with TypeScript
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
PDF
Angular 2 - The Next Framework
PPTX
Async patterns in javascript
PPTX
PDF
Commit University - Exploring Angular 2
PDF
Introduction to Angular 2
PPTX
Migrating an application from Angular 1 to Angular 2
PPTX
Introduction to Angular2
PDF
Exploring Angular 2 - Episode 2
PPTX
Angular 1.x in action now
PPTX
AngularJs presentation
PDF
AngularJS - Services
PDF
Express: A Jump-Start
PDF
Angular 2 Essential Training
PPTX
Angular2 for Beginners
PDF
Angular 2 Crash Course
AngularJS2 / TypeScript / CLI
Angular2 + rxjs
Angular2 with TypeScript
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Angular 2 - The Next Framework
Async patterns in javascript
Commit University - Exploring Angular 2
Introduction to Angular 2
Migrating an application from Angular 1 to Angular 2
Introduction to Angular2
Exploring Angular 2 - Episode 2
Angular 1.x in action now
AngularJs presentation
AngularJS - Services
Express: A Jump-Start
Angular 2 Essential Training
Angular2 for Beginners
Angular 2 Crash Course
Ad

Viewers also liked (20)

PDF
Meet.php #gpio
PDF
Angular2 - Co jest grane?!?!
PDF
GoLang & GoatCore
PDF
Automatyzacja w ng świecie - ng-poznań 11 września 2014
PPTX
IoT dla programistów
PDF
Fosdem i inne konferencje
PDF
Ng poznan 12.06
PDF
Go dla elektronika
PDF
Overview of AngularJS
PDF
Angular 2 MVD workshop
PPTX
Angular2 workshop
PDF
Connected home - market evolution & protocol wars
PDF
Angular2 with type script
PDF
How Angular2 Can Improve Your AngularJS Apps Today!
PDF
Angular2 - getting-ready
PPTX
Angular2 + New Firebase in Action
PDF
Progressive Web Apps: trick or real magic? - Maurizio Mangione - Codemotion M...
PDF
Angular 2 overview
Meet.php #gpio
Angular2 - Co jest grane?!?!
GoLang & GoatCore
Automatyzacja w ng świecie - ng-poznań 11 września 2014
IoT dla programistów
Fosdem i inne konferencje
Ng poznan 12.06
Go dla elektronika
Overview of AngularJS
Angular 2 MVD workshop
Angular2 workshop
Connected home - market evolution & protocol wars
Angular2 with type script
How Angular2 Can Improve Your AngularJS Apps Today!
Angular2 - getting-ready
Angular2 + New Firebase in Action
Progressive Web Apps: trick or real magic? - Maurizio Mangione - Codemotion M...
Angular 2 overview
Ad

Similar to Angular2 - In Action (18)

DOCX
anugula2setupbyshubham
PPTX
Angularjs2 presentation
PDF
better-apps-angular-2-day1.pdf and home
PPTX
Peggy angular 2 in meteor
PPTX
Angularj2.0
PDF
Angular 2 overview in 60 minutes
PPTX
Migrating an Application from Angular 1 to Angular 2
PDF
Building Powerful Applications with AngularJS 2 and TypeScript - David Giard
PDF
Angular 2 for Java Developers
PDF
Angular2
PDF
Angular Notes.pdf
PPTX
From Angular to Angular 2 via the UpgradeAdapter
PPTX
mobile development using node js and java
PPTX
Angular2 and TypeScript
DOCX
Angular2RoutingSetupByShubham
PPTX
Building a TV show with Angular, Bootstrap, and Web Services
PPTX
Angular2 getting started by Stephen Lautier
PDF
Angular 2 introduction
anugula2setupbyshubham
Angularjs2 presentation
better-apps-angular-2-day1.pdf and home
Peggy angular 2 in meteor
Angularj2.0
Angular 2 overview in 60 minutes
Migrating an Application from Angular 1 to Angular 2
Building Powerful Applications with AngularJS 2 and TypeScript - David Giard
Angular 2 for Java Developers
Angular2
Angular Notes.pdf
From Angular to Angular 2 via the UpgradeAdapter
mobile development using node js and java
Angular2 and TypeScript
Angular2RoutingSetupByShubham
Building a TV show with Angular, Bootstrap, and Web Services
Angular2 getting started by Stephen Lautier
Angular 2 introduction

More from Sebastian Pożoga (14)

PDF
Hardgroup - Raspberry PI #1
PDF
Sails.js - Overview
PDF
3D Printing
PDF
PDF
Game jump frontend introduction #workshop1
PDF
Game jump: frontend introduction #1
PDF
The future of technologies
PDF
gameJUMP.pl#about
PDF
Poznań 4.04.2013
PDF
Programming style
PDF
Blender3 d
PDF
Events poznań 7.02.2013
PDF
Events Poznań 18.01.2013
Hardgroup - Raspberry PI #1
Sails.js - Overview
3D Printing
Game jump frontend introduction #workshop1
Game jump: frontend introduction #1
The future of technologies
gameJUMP.pl#about
Poznań 4.04.2013
Programming style
Blender3 d
Events poznań 7.02.2013
Events Poznań 18.01.2013

Recently uploaded (20)

PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Basic Mud Logging Guide for educational purpose
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
master seminar digital applications in india
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Renaissance Architecture: A Journey from Faith to Humanism
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
2.FourierTransform-ShortQuestionswithAnswers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Basic Mud Logging Guide for educational purpose
O7-L3 Supply Chain Operations - ICLT Program
01-Introduction-to-Information-Management.pdf
Final Presentation General Medicine 03-08-2024.pptx
RMMM.pdf make it easy to upload and study
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
master seminar digital applications in india
Microbial disease of the cardiovascular and lymphatic systems
O5-L3 Freight Transport Ops (International) V1.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Angular2 - In Action