SlideShare uma empresa Scribd logo
1 de 59
Baixar para ler offline
Angular 2
IN ACTION
NG2 INTRODUCTION
Part 2
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

AngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLIAngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLI
 
Angular2 + rxjs
Angular2 + rxjsAngular2 + rxjs
Angular2 + rxjs
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascript
 
Angular 5
Angular 5Angular 5
Angular 5
 
Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University - Exploring Angular 2
Commit University - Exploring Angular 2
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2
 
Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2
 
Angular 1.x in action now
Angular 1.x in action nowAngular 1.x in action now
Angular 1.x in action now
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Express: A Jump-Start
Express: A Jump-StartExpress: A Jump-Start
Express: A Jump-Start
 
Angular 2 Essential Training
Angular 2 Essential Training Angular 2 Essential Training
Angular 2 Essential Training
 
Angular2
Angular2Angular2
Angular2
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash Course
 

Destaque

GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
Sebastian Pożoga
 

Destaque (20)

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

Semelhante a Angular2 - In Action

How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 

Semelhante a Angular2 - In Action (20)

Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
We sport architecture_implementation
We sport architecture_implementationWe sport architecture_implementation
We sport architecture_implementation
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
Peggy angular 2 in meteor
Peggy   angular 2 in meteorPeggy   angular 2 in meteor
Peggy angular 2 in meteor
 
A re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbaiA re introduction to webpack - reactfoo - mumbai
A re introduction to webpack - reactfoo - mumbai
 
Requirejs
RequirejsRequirejs
Requirejs
 
Angular Notes.pdf
Angular Notes.pdfAngular Notes.pdf
Angular Notes.pdf
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization development
 
Node.js server-side rendering
Node.js server-side renderingNode.js server-side rendering
Node.js server-side rendering
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 

Mais de Sebastian Pożoga

Mais de Sebastian Pożoga (14)

Hardgroup - Raspberry PI #1
Hardgroup - Raspberry PI #1Hardgroup - Raspberry PI #1
Hardgroup - Raspberry PI #1
 
Sails.js - Overview
Sails.js - OverviewSails.js - Overview
Sails.js - Overview
 
3D Printing
3D Printing3D Printing
3D Printing
 
OSFile#2
OSFile#2OSFile#2
OSFile#2
 
Game jump frontend introduction #workshop1
Game jump  frontend introduction #workshop1Game jump  frontend introduction #workshop1
Game jump frontend introduction #workshop1
 
Game jump: frontend introduction #1
Game jump: frontend introduction #1Game jump: frontend introduction #1
Game jump: frontend introduction #1
 
The future of technologies
The future of technologiesThe future of technologies
The future of technologies
 
OSFile
OSFileOSFile
OSFile
 
gameJUMP.pl#about
gameJUMP.pl#aboutgameJUMP.pl#about
gameJUMP.pl#about
 
Poznań 4.04.2013
Poznań 4.04.2013Poznań 4.04.2013
Poznań 4.04.2013
 
Programming style
Programming styleProgramming style
Programming style
 
Blender3 d
Blender3 dBlender3 d
Blender3 d
 
Events poznań 7.02.2013
Events poznań 7.02.2013Events poznań 7.02.2013
Events poznań 7.02.2013
 
Events Poznań 18.01.2013
Events Poznań 18.01.2013Events Poznań 18.01.2013
Events Poznań 18.01.2013
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Último (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

Angular2 - In Action