SlideShare a Scribd company logo
1 of 21
Angular 2 in Meteor
PEGGY
2015-09-11
Install Angular 2
 Angular 2 Package
 meteor add shmck:angular2
 TypeScript
 meteor add netanelgilad:angular2-typescript
System.js
 System.js is a module loader built into the shmck:angular2 package. We'll
use it to load our root component.
 Import bootstrap component with System.js
<body>
<p>Nothing here</p>
<script>System.import("client/app");</script>
</body>
Root Component - client/index.html
 A component is a controller with an attached view. Think of it like a brick in
the castle of your app.
 We'll create a root component tag called app. Let's include that
component into our main index.html file:
<body>
<app></app>
<script>System.import("client/app");</script>
</body>
client/app.ts
 First we're importing the dependencies we needed from
angular2/angular2. This is not a folder and file in your directory, but
referring to an alias provided to System.js in the shmck:angular2 package.
 Notice the @ syntax. In Angular 2, these are called Annotations.
import {Component, View, bootstrap} from 'angular2/angular2';
@Component({ selector: 'app' })
@View({ template: "<p>Hello World!</p>" })
class Socially {}
bootstrap(Socially);
templateUrl
 client/app.ts
 client/index.ng.html
import {Component, View, bootstrap} from 'angular2/angular2';
@Component({ selector: 'app' })
@View({ templateUrl: "client/index.ng.html" })
class Socially {}
bootstrap(Socially);
<p>Nothing here {{ 'yet' + '!' }}</p>
View
 The syntax is very easy:
 {{ expression | pipe }} - Angular 2 interpolation,
 #variable – local variables available in the scope of the component. The
variable can be later referred in the component’s template,
 (event) - binding to events of element or directive,
 [property] - binding to properties of element.
 *property - the star means that it is a template
 Ref. http://blog.codeleak.pl/2015/06/angular2hello-world.html
Data in the View
 The *ng-for="party of parties" attribute in the li tag is an Angular repeater
directive.
<div>
<ul>
<li *ng-for="#party of parties"> {{party.name}}
<p>{{party.description}}</p>
</li>
</ul>
</div>
Model and Controller
import {Component, View, NgFor, bootstrap} from 'angular2/angular2';
@Component({ selector: 'app' })
@View({
templateUrl: "client/index.ng.html",
directives: [NgFor] })
class Socially {
constructor () {
this.parties = [
{'name': 'Dubstep-Free Zone', 'description': 'Can we please just for an evening not listen to dubstep.'},
{'name': 'All dubstep all the time', 'description': 'Get it on!'},
{'name': 'Savage lounging', 'description': 'Leisure suit required. And only fiercest manners.'} ];
}
}
bootstrap(Socially);
Use Collection
 Use Meteor Tracker, a reactive wrapper that we will run data when a
change occurs.
 The fat arrow syntax => is also from ES2015, and tells the function to run in
it's parents context.
 model/parties.ts
 client/app.ts
Parties = new Mongo.Collection("parties");
constructor() { this.parties = Parties.find().fetch(); }
Meteor Tracker
 A reactive wrapper that we will run data when a change occurs.
 We will bind it to Angular's change detection system, Zone.js.
class Socially {
constructor () {
Tracker.autorun(zone.bind(() => {
this.parties = Parties.find().fetch();
}));
}
}
Model Driven Forms
 We are binding this.partiesForm here to a Control Group. Think of a control
group as a wrapper for a group of form controls.
export class PartiesForm {
constructor() {
this.partiesForm = new ControlGroup({
name: new Control(''),
description: new Control('')
});
}
<form [ng-form-model]="partiesForm">
<label>Name</label>
<input type="text" ng-control="name">
<label>Description</label>
<input type="text" ng-control="description">
<button>Add</button>
</form>
Two-way Bindings
 Property bindings are used to pass data from the parent to the child, and
event bindings are used to pass data from the child to the parent. So we
can use the two to implement two-way bindings.
 And since this is such a common pattern, Angular provides syntax sugar to
remove the boilerplate.
 Ref. http://victorsavkin.com/post/119943127151/angular-2-template-syntax
<input [ng-model]="todo.text" (ng-model)="todo.text=$event"></input>
<input [(ng-model)]="todo.text"></input>
Router
Router
 Install
 meteor add shmck:angular2-router
import {Component, View, bootstrap} from 'angular2/angular2';
import {routerInjectables, routerDirectives, Router, RouteConfig} from 'angular2/router';
@Component({ selector: 'app' })
@View({
template: '<router-outlet></router-outlet>‘,
Directives: [routerDirectives]
})
@RouteConfig()
class Socially {}
bootstrap(Socially, [routerInjectables]);
Router - 2
 imports from 'angular2/router'
 @RouteConfig() which will specify our routes
 View directives adding routerDirectives, allowing us to communicate with
the view
 inject routerInjectables into the child components
 a location where components will be created, the <router-outlet></router-
outlet>
 declare the base route in index.html (required when using the
HTML5LocationStrategy, rather than the HashLocationStategy)
Configuring Routes - client/app.ts
 as: alias
import {PartiesList} from 'client/parties-list/parties-list';
import {PartyDetails} from 'client/party-details/party-details';
@Component( ... )
@View( ... )
@RouteConfig([
{path: '/', component: PartiesList},
{path: '/party/:partyId', as: 'party-details', component: PartyDetails}
])
Problem
 Event Bubbling
 Clicking elements inside that div won’t trigger the event handler.
 We have to be explicit by adding ^ symbol to our binding
 Ref. http://blog.thoughtram.io/angular/2015/08/11/angular-2-template-syntax-
demystified-part-1.html
<div (click)="statement()">
<div></div>
</div>
<div (^click)="statement()">
<div></div>
</div>
<div (click)="statement()"> </div>
Problem
 Zone.js
 Zone.bind()
Meteor.call("test", function(e, n){
this.result = n;
}) ;
Meteor.call("test", (e, n)=>{
this.result = n;
}) ;
Meteor.call("test", zone.bind((e, n)=>{
this.result = n;
})) ;

More Related Content

What's hot

Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next FrameworkCommit University
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesMarios Fakiolas
 
Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - ServicesNir Kaufman
 
Understand components in Angular 2
Understand components in Angular 2Understand components in Angular 2
Understand components in Angular 2codeandyou forums
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascriptRan Wahle
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2Demey Emmanuel
 
ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2Demey Emmanuel
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developementpeychevi
 
ngNewRouter
ngNewRouterngNewRouter
ngNewRouterphidong
 
Creating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with ReactCreating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with Reactpeychevi
 
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 2016Codemotion
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xEyal Vardi
 

What's hot (20)

Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directives
 
Commit University - Exploring Angular 2
Commit University - Exploring Angular 2Commit University - Exploring Angular 2
Commit University - Exploring Angular 2
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Angular2
Angular2Angular2
Angular2
 
Understand components in Angular 2
Understand components in Angular 2Understand components in Angular 2
Understand components in Angular 2
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascript
 
Solid angular
Solid angularSolid angular
Solid angular
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2
 
ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developement
 
ngNewRouter
ngNewRouterngNewRouter
ngNewRouter
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Creating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with ReactCreating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with React
 
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
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
 

Similar to Peggy angular 2 in meteor

Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2Paras Mendiratta
 
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.0Frost
 
Angular2RoutingSetupByShubham
Angular2RoutingSetupByShubhamAngular2RoutingSetupByShubham
Angular2RoutingSetupByShubhamShubham Verma
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Ontico
 
Angular Notes.pdf
Angular Notes.pdfAngular Notes.pdf
Angular Notes.pdfsagarpal60
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6William Marques
 
Migrating to Angular 2
Migrating to Angular 2Migrating to Angular 2
Migrating to Angular 2FITC
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...Katy Slemon
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Ahmed Moawad
 
はじめてのAngular2
はじめてのAngular2はじめてのAngular2
はじめてのAngular2Kenichi Kanai
 
هیبرید کارا، از رویا تا واقعیت!
هیبرید کارا، از رویا تا واقعیت!هیبرید کارا، از رویا تا واقعیت!
هیبرید کارا، از رویا تا واقعیت!Web Standards School
 
angular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfangular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfNuttavutThongjor1
 
anugula2setupbyshubham
anugula2setupbyshubhamanugula2setupbyshubham
anugula2setupbyshubhamShubham Verma
 
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법Jeado Ko
 

Similar to Peggy angular 2 in meteor (20)

Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
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
 
Angular2RoutingSetupByShubham
Angular2RoutingSetupByShubhamAngular2RoutingSetupByShubham
Angular2RoutingSetupByShubham
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
Angular Notes.pdf
Angular Notes.pdfAngular Notes.pdf
Angular Notes.pdf
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Migrating to Angular 2
Migrating to Angular 2Migrating to Angular 2
Migrating to Angular 2
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
 
Angular 2 in-1
Angular 2 in-1 Angular 2 in-1
Angular 2 in-1
 
Angular 2 - a New Hope
Angular 2 - a New HopeAngular 2 - a New Hope
Angular 2 - a New Hope
 
はじめてのAngular2
はじめてのAngular2はじめてのAngular2
はじめてのAngular2
 
Routing to components
Routing to componentsRouting to components
Routing to components
 
mean stack
mean stackmean stack
mean stack
 
هیبرید کارا، از رویا تا واقعیت!
هیبرید کارا، از رویا تا واقعیت!هیبرید کارا، از رویا تا واقعیت!
هیبرید کارا، از رویا تا واقعیت!
 
angular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfangular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdf
 
anugula2setupbyshubham
anugula2setupbyshubhamanugula2setupbyshubham
anugula2setupbyshubham
 
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-redux
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Angular routing
Angular routingAngular routing
Angular routing
 

More from LearningTech

More from LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Peggy angular 2 in meteor

  • 1. Angular 2 in Meteor PEGGY 2015-09-11
  • 2. Install Angular 2  Angular 2 Package  meteor add shmck:angular2  TypeScript  meteor add netanelgilad:angular2-typescript
  • 3. System.js  System.js is a module loader built into the shmck:angular2 package. We'll use it to load our root component.  Import bootstrap component with System.js <body> <p>Nothing here</p> <script>System.import("client/app");</script> </body>
  • 4. Root Component - client/index.html  A component is a controller with an attached view. Think of it like a brick in the castle of your app.  We'll create a root component tag called app. Let's include that component into our main index.html file: <body> <app></app> <script>System.import("client/app");</script> </body>
  • 5. client/app.ts  First we're importing the dependencies we needed from angular2/angular2. This is not a folder and file in your directory, but referring to an alias provided to System.js in the shmck:angular2 package.  Notice the @ syntax. In Angular 2, these are called Annotations. import {Component, View, bootstrap} from 'angular2/angular2'; @Component({ selector: 'app' }) @View({ template: "<p>Hello World!</p>" }) class Socially {} bootstrap(Socially);
  • 6. templateUrl  client/app.ts  client/index.ng.html import {Component, View, bootstrap} from 'angular2/angular2'; @Component({ selector: 'app' }) @View({ templateUrl: "client/index.ng.html" }) class Socially {} bootstrap(Socially); <p>Nothing here {{ 'yet' + '!' }}</p>
  • 7.
  • 8. View  The syntax is very easy:  {{ expression | pipe }} - Angular 2 interpolation,  #variable – local variables available in the scope of the component. The variable can be later referred in the component’s template,  (event) - binding to events of element or directive,  [property] - binding to properties of element.  *property - the star means that it is a template  Ref. http://blog.codeleak.pl/2015/06/angular2hello-world.html
  • 9. Data in the View  The *ng-for="party of parties" attribute in the li tag is an Angular repeater directive. <div> <ul> <li *ng-for="#party of parties"> {{party.name}} <p>{{party.description}}</p> </li> </ul> </div>
  • 10. Model and Controller import {Component, View, NgFor, bootstrap} from 'angular2/angular2'; @Component({ selector: 'app' }) @View({ templateUrl: "client/index.ng.html", directives: [NgFor] }) class Socially { constructor () { this.parties = [ {'name': 'Dubstep-Free Zone', 'description': 'Can we please just for an evening not listen to dubstep.'}, {'name': 'All dubstep all the time', 'description': 'Get it on!'}, {'name': 'Savage lounging', 'description': 'Leisure suit required. And only fiercest manners.'} ]; } } bootstrap(Socially);
  • 11. Use Collection  Use Meteor Tracker, a reactive wrapper that we will run data when a change occurs.  The fat arrow syntax => is also from ES2015, and tells the function to run in it's parents context.  model/parties.ts  client/app.ts Parties = new Mongo.Collection("parties"); constructor() { this.parties = Parties.find().fetch(); }
  • 12. Meteor Tracker  A reactive wrapper that we will run data when a change occurs.  We will bind it to Angular's change detection system, Zone.js. class Socially { constructor () { Tracker.autorun(zone.bind(() => { this.parties = Parties.find().fetch(); })); } }
  • 13. Model Driven Forms  We are binding this.partiesForm here to a Control Group. Think of a control group as a wrapper for a group of form controls. export class PartiesForm { constructor() { this.partiesForm = new ControlGroup({ name: new Control(''), description: new Control('') }); } <form [ng-form-model]="partiesForm"> <label>Name</label> <input type="text" ng-control="name"> <label>Description</label> <input type="text" ng-control="description"> <button>Add</button> </form>
  • 14. Two-way Bindings  Property bindings are used to pass data from the parent to the child, and event bindings are used to pass data from the child to the parent. So we can use the two to implement two-way bindings.  And since this is such a common pattern, Angular provides syntax sugar to remove the boilerplate.  Ref. http://victorsavkin.com/post/119943127151/angular-2-template-syntax <input [ng-model]="todo.text" (ng-model)="todo.text=$event"></input> <input [(ng-model)]="todo.text"></input>
  • 16. Router  Install  meteor add shmck:angular2-router import {Component, View, bootstrap} from 'angular2/angular2'; import {routerInjectables, routerDirectives, Router, RouteConfig} from 'angular2/router'; @Component({ selector: 'app' }) @View({ template: '<router-outlet></router-outlet>‘, Directives: [routerDirectives] }) @RouteConfig() class Socially {} bootstrap(Socially, [routerInjectables]);
  • 17. Router - 2  imports from 'angular2/router'  @RouteConfig() which will specify our routes  View directives adding routerDirectives, allowing us to communicate with the view  inject routerInjectables into the child components  a location where components will be created, the <router-outlet></router- outlet>  declare the base route in index.html (required when using the HTML5LocationStrategy, rather than the HashLocationStategy)
  • 18. Configuring Routes - client/app.ts  as: alias import {PartiesList} from 'client/parties-list/parties-list'; import {PartyDetails} from 'client/party-details/party-details'; @Component( ... ) @View( ... ) @RouteConfig([ {path: '/', component: PartiesList}, {path: '/party/:partyId', as: 'party-details', component: PartyDetails} ])
  • 19.
  • 20. Problem  Event Bubbling  Clicking elements inside that div won’t trigger the event handler.  We have to be explicit by adding ^ symbol to our binding  Ref. http://blog.thoughtram.io/angular/2015/08/11/angular-2-template-syntax- demystified-part-1.html <div (click)="statement()"> <div></div> </div> <div (^click)="statement()"> <div></div> </div> <div (click)="statement()"> </div>
  • 21. Problem  Zone.js  Zone.bind() Meteor.call("test", function(e, n){ this.result = n; }) ; Meteor.call("test", (e, n)=>{ this.result = n; }) ; Meteor.call("test", zone.bind((e, n)=>{ this.result = n; })) ;