SlideShare a Scribd company logo
1 of 20
Download to read offline
SPQR
Erik Witt
Florian Bücklers
Building an Angular 2 App
@baqendcom
Speaker Question Round
http://tiny.cc/spqr
Who we are
• Many years of experience in web dev
• Both frontend and backend
• Many Angular 1 projects
• Very curious about Angular 2  introduced it in a
production web platform
• What we do: developing Baqend, a serverless
backend for faster websites and apps
• Great match for Angular2 (see our Baqend+Angular 2
starter kit)
Angular 2
• A framework to build client-side applications
• Code can be written in Typescript, ES6, Dart or
JavaScript (without transpiling)
• Has an expressive template language
• Powerful data binding
• Available as release candidate 4 (07/26/2016)
Why Angular 2?
• Fixes many performance pitfalls of Angular 1
• Modern design using ES6 features, e.g.:
• Classes, Template strings
• Simplified API and clearer concepts
• Uses Typescript as the primary language for:
• Interfaces
• Type declarations
• Decorators and Annotations
Project Setup
• We use System.js to load ES6 based modules
• Also Webpack or browserify can be used
• Typescript since it is the recommended language
• Hosted on Plunker (http://plnkr.co/)
• Open it: tiny.cc/spqr
Components
• Components are the main classes where most of
our code is
• Template:
• Mostly HTML with some additional instructions
• Styles are scoped to the component (similar to Web
Components)
• Component Class:
• Methods and properties that can be accessed and
invoked from the rendered page
• Metadata specified in Decorators:
• Additional instructions like pipes and directives
Template expressions
• Model to view binding for values and properties
• View to model binding
• View to model & model to view (2-way-binding)
<div [class.active]="question.state == 'active'">
<span class="badge">{{question.votes}}</span>
<div (click)="onClick($event)"></div>
<input [(ngModel)]="value"></input>
<!-- short hand for -->
<input [ngModel]="value" (ngModel)="value = $event"></input>
Structural Directives *ngIf, *ngFor
• *ngIf conditionally renders a template
• *ngFor loops over a collection
<!-- *ngIf paragraph -->
<div *ngIf="questions">
We have some questions
</div>
<!-- [ngIf] with template -->
<template [ngIf]="questions ">
<div>
We have some questions
</div>
</template>
<div *ngFor="let question of questions">{{question.question}}</div>
Forms
• ngModel adds two-way binding between model
and input value
• ngSubmit handles form submissions
• Access to the form controller ngForm
<input type="text" [(ngModel)]="newQuestion" name="question" required>
<form (ngSubmit)="ask(newQuestion)">
<form #questionForm="ngForm" (ngSubmit)="ask(questionForm.value)">
…
<button type="submit" [disabled]="!questionForm.valid">Ask</button>
</form>
Services
• Services are useful to share common code between
different controllers.
• Services are injectable, so they can be used in any
Component / Pipe / Directive …
• Services are created by Angular when they are first
requested and are treated as singletons
@Injectable()
export class StorageService {
export class TalkComponent {
//StorageService is injected to the component by angular
constructor(private storageService:StorageService) {}
Pipes
• Pipes are template helpers to transform values
• Pipes are pure by default
• A pure pipe is only invoked if its primitive input changed
or the reference of an object changed
• Impure Pipes
• Needed if the pipe must be reevaluated when
properties of an object changed or elements of an array
are updated
• Are always evaluated (expensive)
<small>{{question.date | date:'shortTime'}}</small>
Router
• Routes are defined as URL patterns and handled by
a target component
• Matching route parameters can be accesses by
injecting the ActivatedRoute
const routes: RouterConfig = [
{ path: 'talk/:id', component: TalkComponent }
];
export class TalkComponent {
constructor(private route: ActivatedRoute) {}
ngOnInit() {
let id = this.route.snapshot.params['id'];
}
}
Router Navigation
• The routerLink directive can be used to navigate to a
another route
• The router can be used to navigate programmatically
• Highlight active route links by setting a class
<a routerLink="/login">Login</a>
constructor(private router: Router)
navigate(talk) {
this.router.navigate(['/talk', talk.id]);
}
<a routerLink="/login" routerLinkActive="active">Login</a>
Route Subscription
• You can also subscribe to route parameter changes
• Prevents recreating and redrawing the component when
only a parameter changes
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
let id = params['id'];
});
}
ngOnDestroy() {
this.sub.unsubscribe();
}
Directives
• Extend the behavior of HTML
• Most directives introduce new attributes or HTML
elements
• The controller can be exposed with exportAs
• Controller methods can be used within the
template
@Directive({
selector: '[collapse]',
exportAs: 'Collapse'
})
export class CollapseDirective {
<button type="button" (click)="navbar.toggle()"></button>
<div collapse #navbar="Collapse">
Model to directive binding
• A directive has no direct access to outer scope
• Instead model data can bind to a directive
• The directive subscribes to changes
export class CollapseDirective {
@Input() collapse:boolean;
ngOnChanges(changes: {[propKey: string]: SimpleChange}) {
if (changes.collapse) {
//changed by model
let from = changes.collapse.previousValue;
let to = changes.collapse.currentValue;
}
}
}
<div [collapse]="navbarCollapse">
Directive to model binding
• A directive has no direct access to the outer scope
• Data can be sent to the model
• And be subscribed to in the view
<div (collapse)="navbarCollapse = $event">
export class CollapseDirective {
@Output() collapse = new EventEmitter<boolean>();
toggle() {
this.expanded = !this.expanded;
this.collapse.emit(this.expanded);
}
}
Directive <-> model binding
• Binding can be two-way, similar to components:
<div [(collapse)]="navbarCollapse">
export class CollapseDirective {
@Input() collapse:boolean;
@Output() collapseChange = new EventEmitter<boolean>();
ngOnChanges(changes: {[propKey: string]: SimpleChange}) {
if (changes.collapse)
//changed by model
}
toggle() {
this. collapseChange.emit(!this.expanded);
}
}
Thank you!
{fb,ew}@baqend.com
http://www.baqend.com/guide/starters/
http://tiny.cc/spqr

More Related Content

What's hot

JClouds at San Francisco Java User Group
JClouds at San Francisco Java User GroupJClouds at San Francisco Java User Group
JClouds at San Francisco Java User GroupMarakana Inc.
 
Secrets in Kubernetes
Secrets in KubernetesSecrets in Kubernetes
Secrets in KubernetesJerry Jalava
 
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
NATS: Simple, Secure and Scalable Messaging For the Cloud Native EraNATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Erawallyqs
 
On Docker and its use for LHC at CERN
On Docker and its use for LHC at CERNOn Docker and its use for LHC at CERN
On Docker and its use for LHC at CERNSebastien Goasguen
 
Lessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure codeLessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure codeYevgeniy Brikman
 
Storage as a service and OpenStack Cinder
Storage as a service and OpenStack CinderStorage as a service and OpenStack Cinder
Storage as a service and OpenStack Cinderopenstackindia
 
Docker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12cDocker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12cFrank Munz
 
Clocker - How to Train your Docker Cloud
Clocker - How to Train your Docker CloudClocker - How to Train your Docker Cloud
Clocker - How to Train your Docker CloudAndrew Kennedy
 
Openstack Study Nova 1
Openstack Study Nova 1Openstack Study Nova 1
Openstack Study Nova 1Jinho Shin
 
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Codemotion
 
VMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - OverviewVMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - Overviewrajdeep
 
Quick overview of Openstack architecture
Quick overview of Openstack architectureQuick overview of Openstack architecture
Quick overview of Openstack architectureToni Ramirez
 
OpenStack Introduction
OpenStack IntroductionOpenStack Introduction
OpenStack Introductionopenstackindia
 
Orchestration & provisioning
Orchestration & provisioningOrchestration & provisioning
Orchestration & provisioningbuildacloud
 
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...MongoDB
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkLuciano Mammino
 

What's hot (20)

JClouds at San Francisco Java User Group
JClouds at San Francisco Java User GroupJClouds at San Francisco Java User Group
JClouds at San Francisco Java User Group
 
Secrets in Kubernetes
Secrets in KubernetesSecrets in Kubernetes
Secrets in Kubernetes
 
Kubernetes: My BFF
Kubernetes: My BFFKubernetes: My BFF
Kubernetes: My BFF
 
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
NATS: Simple, Secure and Scalable Messaging For the Cloud Native EraNATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
 
On Docker and its use for LHC at CERN
On Docker and its use for LHC at CERNOn Docker and its use for LHC at CERN
On Docker and its use for LHC at CERN
 
Lessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure codeLessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure code
 
Storage as a service and OpenStack Cinder
Storage as a service and OpenStack CinderStorage as a service and OpenStack Cinder
Storage as a service and OpenStack Cinder
 
Docker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12cDocker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12c
 
Clocker and OpenStack
Clocker and OpenStackClocker and OpenStack
Clocker and OpenStack
 
OpenStack Storage Overview
OpenStack Storage OverviewOpenStack Storage Overview
OpenStack Storage Overview
 
Clocker - How to Train your Docker Cloud
Clocker - How to Train your Docker CloudClocker - How to Train your Docker Cloud
Clocker - How to Train your Docker Cloud
 
Openstack Study Nova 1
Openstack Study Nova 1Openstack Study Nova 1
Openstack Study Nova 1
 
OpenStack Cinder
OpenStack CinderOpenStack Cinder
OpenStack Cinder
 
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
 
VMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - OverviewVMware Hybrid Cloud Service - Overview
VMware Hybrid Cloud Service - Overview
 
Quick overview of Openstack architecture
Quick overview of Openstack architectureQuick overview of Openstack architecture
Quick overview of Openstack architecture
 
OpenStack Introduction
OpenStack IntroductionOpenStack Introduction
OpenStack Introduction
 
Orchestration & provisioning
Orchestration & provisioningOrchestration & provisioning
Orchestration & provisioning
 
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
 

Viewers also liked

Cache Sketches: Using Bloom Filters and Web Caching Against Slow Load Times
Cache Sketches: Using Bloom Filters and Web Caching Against Slow Load TimesCache Sketches: Using Bloom Filters and Web Caching Against Slow Load Times
Cache Sketches: Using Bloom Filters and Web Caching Against Slow Load TimesFelix Gessert
 
Bloom Filters for Web Caching - Lightning Talk
Bloom Filters for Web Caching - Lightning TalkBloom Filters for Web Caching - Lightning Talk
Bloom Filters for Web Caching - Lightning TalkFelix Gessert
 
Web Performance – die effektivsten Techniken aus der Praxis
Web Performance – die effektivsten Techniken aus der PraxisWeb Performance – die effektivsten Techniken aus der Praxis
Web Performance – die effektivsten Techniken aus der PraxisFelix Gessert
 
Cloud Databases in Research and Practice
Cloud Databases in Research and PracticeCloud Databases in Research and Practice
Cloud Databases in Research and PracticeFelix Gessert
 
Pitch auf den Hamburger IT-Strategietagen
Pitch auf den Hamburger IT-StrategietagenPitch auf den Hamburger IT-Strategietagen
Pitch auf den Hamburger IT-StrategietagenFelix Gessert
 
Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013
Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013
Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013Amazon Web Services
 
Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...
Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...
Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...Amazon Web Services
 

Viewers also liked (8)

Cache Sketches: Using Bloom Filters and Web Caching Against Slow Load Times
Cache Sketches: Using Bloom Filters and Web Caching Against Slow Load TimesCache Sketches: Using Bloom Filters and Web Caching Against Slow Load Times
Cache Sketches: Using Bloom Filters and Web Caching Against Slow Load Times
 
Bloom Filters for Web Caching - Lightning Talk
Bloom Filters for Web Caching - Lightning TalkBloom Filters for Web Caching - Lightning Talk
Bloom Filters for Web Caching - Lightning Talk
 
Web Performance – die effektivsten Techniken aus der Praxis
Web Performance – die effektivsten Techniken aus der PraxisWeb Performance – die effektivsten Techniken aus der Praxis
Web Performance – die effektivsten Techniken aus der Praxis
 
Cloud Databases in Research and Practice
Cloud Databases in Research and PracticeCloud Databases in Research and Practice
Cloud Databases in Research and Practice
 
Pitch auf den Hamburger IT-Strategietagen
Pitch auf den Hamburger IT-StrategietagenPitch auf den Hamburger IT-Strategietagen
Pitch auf den Hamburger IT-Strategietagen
 
Intro to Baqend
Intro to BaqendIntro to Baqend
Intro to Baqend
 
Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013
Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013
Trusted Analytics as a Service (BDT209) | AWS re:Invent 2013
 
Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...
Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...
Enabling Innovative Business Opportunities Through Secure Cloud Adoption - Se...
 

Similar to Building an Angular 2 App

Angular 2 at solutions.hamburg
Angular 2 at solutions.hamburgAngular 2 at solutions.hamburg
Angular 2 at solutions.hamburgBaqend
 
Angular js 2
Angular js 2Angular js 2
Angular js 2Ran Wahle
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcdenemedeniz
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introductioncherukumilli2
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017Matt Raible
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcherlottepitcher
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introductionLuigi De Russis
 
Vue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.jsVue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.jsTakuya Tejima
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletonGeorge Nguyen
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutesLoiane Groner
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPMohammad Shaker
 
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014FalafelSoftware
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-HibernateJay Shah
 

Similar to Building an Angular 2 App (20)

Angular 2 at solutions.hamburg
Angular 2 at solutions.hamburgAngular 2 at solutions.hamburg
Angular 2 at solutions.hamburg
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvc
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Angularjs
AngularjsAngularjs
Angularjs
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017
 
mean stack
mean stackmean stack
mean stack
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
Vue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.jsVue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.js
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutes
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
 
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
 
What's new in Angular 2?
What's new in Angular 2?What's new in Angular 2?
What's new in Angular 2?
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-Hibernate
 
Knolx session
Knolx sessionKnolx session
Knolx session
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
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
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
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
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

Building an Angular 2 App

  • 1. SPQR Erik Witt Florian Bücklers Building an Angular 2 App @baqendcom Speaker Question Round
  • 3. Who we are • Many years of experience in web dev • Both frontend and backend • Many Angular 1 projects • Very curious about Angular 2  introduced it in a production web platform • What we do: developing Baqend, a serverless backend for faster websites and apps • Great match for Angular2 (see our Baqend+Angular 2 starter kit)
  • 4. Angular 2 • A framework to build client-side applications • Code can be written in Typescript, ES6, Dart or JavaScript (without transpiling) • Has an expressive template language • Powerful data binding • Available as release candidate 4 (07/26/2016)
  • 5. Why Angular 2? • Fixes many performance pitfalls of Angular 1 • Modern design using ES6 features, e.g.: • Classes, Template strings • Simplified API and clearer concepts • Uses Typescript as the primary language for: • Interfaces • Type declarations • Decorators and Annotations
  • 6. Project Setup • We use System.js to load ES6 based modules • Also Webpack or browserify can be used • Typescript since it is the recommended language • Hosted on Plunker (http://plnkr.co/) • Open it: tiny.cc/spqr
  • 7. Components • Components are the main classes where most of our code is • Template: • Mostly HTML with some additional instructions • Styles are scoped to the component (similar to Web Components) • Component Class: • Methods and properties that can be accessed and invoked from the rendered page • Metadata specified in Decorators: • Additional instructions like pipes and directives
  • 8. Template expressions • Model to view binding for values and properties • View to model binding • View to model & model to view (2-way-binding) <div [class.active]="question.state == 'active'"> <span class="badge">{{question.votes}}</span> <div (click)="onClick($event)"></div> <input [(ngModel)]="value"></input> <!-- short hand for --> <input [ngModel]="value" (ngModel)="value = $event"></input>
  • 9. Structural Directives *ngIf, *ngFor • *ngIf conditionally renders a template • *ngFor loops over a collection <!-- *ngIf paragraph --> <div *ngIf="questions"> We have some questions </div> <!-- [ngIf] with template --> <template [ngIf]="questions "> <div> We have some questions </div> </template> <div *ngFor="let question of questions">{{question.question}}</div>
  • 10. Forms • ngModel adds two-way binding between model and input value • ngSubmit handles form submissions • Access to the form controller ngForm <input type="text" [(ngModel)]="newQuestion" name="question" required> <form (ngSubmit)="ask(newQuestion)"> <form #questionForm="ngForm" (ngSubmit)="ask(questionForm.value)"> … <button type="submit" [disabled]="!questionForm.valid">Ask</button> </form>
  • 11. Services • Services are useful to share common code between different controllers. • Services are injectable, so they can be used in any Component / Pipe / Directive … • Services are created by Angular when they are first requested and are treated as singletons @Injectable() export class StorageService { export class TalkComponent { //StorageService is injected to the component by angular constructor(private storageService:StorageService) {}
  • 12. Pipes • Pipes are template helpers to transform values • Pipes are pure by default • A pure pipe is only invoked if its primitive input changed or the reference of an object changed • Impure Pipes • Needed if the pipe must be reevaluated when properties of an object changed or elements of an array are updated • Are always evaluated (expensive) <small>{{question.date | date:'shortTime'}}</small>
  • 13. Router • Routes are defined as URL patterns and handled by a target component • Matching route parameters can be accesses by injecting the ActivatedRoute const routes: RouterConfig = [ { path: 'talk/:id', component: TalkComponent } ]; export class TalkComponent { constructor(private route: ActivatedRoute) {} ngOnInit() { let id = this.route.snapshot.params['id']; } }
  • 14. Router Navigation • The routerLink directive can be used to navigate to a another route • The router can be used to navigate programmatically • Highlight active route links by setting a class <a routerLink="/login">Login</a> constructor(private router: Router) navigate(talk) { this.router.navigate(['/talk', talk.id]); } <a routerLink="/login" routerLinkActive="active">Login</a>
  • 15. Route Subscription • You can also subscribe to route parameter changes • Prevents recreating and redrawing the component when only a parameter changes ngOnInit() { this.sub = this.route.params.subscribe(params => { let id = params['id']; }); } ngOnDestroy() { this.sub.unsubscribe(); }
  • 16. Directives • Extend the behavior of HTML • Most directives introduce new attributes or HTML elements • The controller can be exposed with exportAs • Controller methods can be used within the template @Directive({ selector: '[collapse]', exportAs: 'Collapse' }) export class CollapseDirective { <button type="button" (click)="navbar.toggle()"></button> <div collapse #navbar="Collapse">
  • 17. Model to directive binding • A directive has no direct access to outer scope • Instead model data can bind to a directive • The directive subscribes to changes export class CollapseDirective { @Input() collapse:boolean; ngOnChanges(changes: {[propKey: string]: SimpleChange}) { if (changes.collapse) { //changed by model let from = changes.collapse.previousValue; let to = changes.collapse.currentValue; } } } <div [collapse]="navbarCollapse">
  • 18. Directive to model binding • A directive has no direct access to the outer scope • Data can be sent to the model • And be subscribed to in the view <div (collapse)="navbarCollapse = $event"> export class CollapseDirective { @Output() collapse = new EventEmitter<boolean>(); toggle() { this.expanded = !this.expanded; this.collapse.emit(this.expanded); } }
  • 19. Directive <-> model binding • Binding can be two-way, similar to components: <div [(collapse)]="navbarCollapse"> export class CollapseDirective { @Input() collapse:boolean; @Output() collapseChange = new EventEmitter<boolean>(); ngOnChanges(changes: {[propKey: string]: SimpleChange}) { if (changes.collapse) //changed by model } toggle() { this. collapseChange.emit(!this.expanded); } }