SlideShare a Scribd company logo
SPQR
Hannes Kuhlmann
Florian Bücklers
Building an Angular 2 App
@baqendcom
Speaker Question Round
Why Baqend?
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 6 (08/09/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 Baqend
http://spqr.app.baqend.com
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 styles, template 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: Routes = [
{ 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,hk}@baqend.com
http://www.baqend.com/guide/starters/
http://spqr.app.baqend.com

More Related Content

PPTX
Hanselman lipton asp_connections_ams304_mvc
PPTX
Getting Started with Angular JS
PDF
AngularJS 101 - Everything you need to know to get started
PDF
Web components - An Introduction
PDF
Modern Web Application Development Workflow - EclipseCon Europe 2014
PDF
Building Blocks of Angular 2 and ASP.NET Core
PPTX
Angular js 1.3 basic tutorial
Hanselman lipton asp_connections_ams304_mvc
Getting Started with Angular JS
AngularJS 101 - Everything you need to know to get started
Web components - An Introduction
Modern Web Application Development Workflow - EclipseCon Europe 2014
Building Blocks of Angular 2 and ASP.NET Core
Angular js 1.3 basic tutorial

What's hot (20)

PPTX
Angular JS
PPTX
Step by Step - AngularJS
PPTX
Angular js 1.0-fundamentals
PPTX
AngularJS 2.0
PDF
Rambler.iOS #5: Разбираем Massive View Controller
PPTX
AngularJS - Architecture decisions in a large project 
PPTX
SenchaCon 2016: Enterprise Applications, Role Based Access Controls (RBAC) an...
PDF
CraftCamp for Students - Introduction to AngularJS
PDF
AngularJS introduction
PPTX
Web component
PPTX
Introduction to Angularjs
PPTX
Introduction to single page application with angular js
PPTX
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
PDF
AngularJS with RequireJS
PPTX
5 angularjs features
PPTX
AngularJS One Day Workshop
PDF
Angular JS tutorial
PPTX
Angular View Encapsulation
PDF
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
PPTX
Sexy Architecting. VIPER: MVP on steroids
Angular JS
Step by Step - AngularJS
Angular js 1.0-fundamentals
AngularJS 2.0
Rambler.iOS #5: Разбираем Massive View Controller
AngularJS - Architecture decisions in a large project 
SenchaCon 2016: Enterprise Applications, Role Based Access Controls (RBAC) an...
CraftCamp for Students - Introduction to AngularJS
AngularJS introduction
Web component
Introduction to Angularjs
Introduction to single page application with angular js
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
AngularJS with RequireJS
5 angularjs features
AngularJS One Day Workshop
Angular JS tutorial
Angular View Encapsulation
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Sexy Architecting. VIPER: MVP on steroids
Ad

Similar to Angular 2 at solutions.hamburg (20)

PDF
Building an Angular 2 App
PPTX
Fly High With Angular - How to build an app using Angular
PPTX
Angular js 2
PDF
Angular 2 overview in 60 minutes
PPTX
Angular2 + rxjs
PPTX
What's new in Angular 2?
PPTX
Angular 18 course for begineers and experienced
PPTX
Angular 2 KTS
PDF
Angular2 with TypeScript
PDF
Angular 2 - The Next Framework
PPTX
Angular Basics: A Beginner's Guide to Web Development
PPTX
Angular js 2.0 beta
PDF
Angular2 with type script
PDF
Angular2
PPTX
Angular crash course
PDF
Angular 2 introduction
PPTX
Foster - Getting started with Angular
PDF
Angular 2: What's New?
ODP
Angular2
Building an Angular 2 App
Fly High With Angular - How to build an app using Angular
Angular js 2
Angular 2 overview in 60 minutes
Angular2 + rxjs
What's new in Angular 2?
Angular 18 course for begineers and experienced
Angular 2 KTS
Angular2 with TypeScript
Angular 2 - The Next Framework
Angular Basics: A Beginner's Guide to Web Development
Angular js 2.0 beta
Angular2 with type script
Angular2
Angular crash course
Angular 2 introduction
Foster - Getting started with Angular
Angular 2: What's New?
Angular2
Ad

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
L1 - Introduction to python Backend.pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
AI in Product Development-omnex systems
PDF
Digital Strategies for Manufacturing Companies
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPT
Introduction Database Management System for Course Database
CHAPTER 2 - PM Management and IT Context
PTS Company Brochure 2025 (1).pdf.......
L1 - Introduction to python Backend.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Design an Analysis of Algorithms II-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
Softaken Excel to vCard Converter Software.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
AI in Product Development-omnex systems
Digital Strategies for Manufacturing Companies
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Operating system designcfffgfgggggggvggggggggg
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Introduction Database Management System for Course Database

Angular 2 at solutions.hamburg

  • 1. SPQR Hannes Kuhlmann 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 6 (08/09/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 Baqend
  • 8. 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 styles, template and directives
  • 9. 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>
  • 10. 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>
  • 11. 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>
  • 12. 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) {}
  • 13. 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>
  • 14. 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: Routes = [ { path: 'talk/:id', component: TalkComponent } ]; export class TalkComponent { constructor(private route: ActivatedRoute) {} ngOnInit() { let id = this.route.snapshot.params['id']; } }
  • 15. 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>
  • 16. 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(); }
  • 17. 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">
  • 18. 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">
  • 19. 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); } }
  • 20. 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); } }