SlideShare a Scribd company logo
1 of 38
GetTogether
Getting more out of TypeScript and
Angular 2
Ruben Haeck
28/03/2017
2 of 38
Agenda
• Intro
• TypeScript
• From AngularJS to Angular
• Demo
3 of 38
Intro
• Ruben Haeck
– Queaso Systems NV
– 11 jaar ervaring
– rh@queaso.be
4 of 38
Tools
• Visual Studio 2015/2017
– Belangrijk: Web Essentials
• o.a compilatie → TypeScipt, LESS, …
• Visual Studio Code (1.10.2)
• WebStorm
• Google Chrome
• Pluncker → https://plnkr.co
5 of 38
TypeScript
let’s go typed
6 of 38
TypeScript
• Meta language → JavaScript
• Compileert → JavaScript
• By Microsoft, open source
• Uitbreiding JavaScript
– Strongly typed class-based environment
• http://www.typescriptlang.org
7 of 38
TypeScript (JS)
8 of 38
TypeScript (TS)
9 of 38
Voordelen
• Handige → Large-scale JS applications
• Volgt de ECMAScript 6 standaard
• IDE ondersteuning
– Intellisense
• Compile-time type checking
10 of 38
Compile
• NodeJS
• Visual Studio 2015
– Plugin for TypeScript
– Web Essentials extension
• Andere
– TypeScript gecompileerd door TypeScript
• Client side by SystemJS
npm install –g typescript
tsc basics.ts
tsc basics.ts
11 of 38
TypeScript Fundamentals
• Basic types
• Variables
• Functions
– Declaration, overloading
• Interfaces
• Classes
– Constructors, Implemenation, Inheritance
12 of 38
TypeScript Fundamentals
• Generics
• Enums
• Namespaces
• Modules
13 of 38
TypeScript Fundamentals
• Basic types
– any
• Supertype of all types
• Als type niet is gekend → any
– Primitieve types
•number, string, boolean
• Opgelet: Object → interface!
14 of 38
• Array types
• Object type
• Void type
– Enkel als return type → functie
TypeScript Fundamentals
var names: string[]
var names: Array<string>
var car: { name: string, company: string};
car = { name: ‘BMW’, company: ‘Queaso
Systems’}
function logMe(text: string) : void {
console.log(text);
}
15 of 38
TypeScript Fundamentals
• Interfaces
interface IPerson {
name: string;
}
interface IQueasoEmployee extends IPerson {
happy: boolean;
age: number;
savePerson(person: IPerson): void;
}
multiple inheritance
16 of 38
TypeScript Fundamentals
• Classes
– Instance members
– Static members
– Access modifiers
– Constructors
– Interface implementation
– Class inheritance
17 of 38
TypeScript Fundamentals
class Employee {
// # constructor(s)
constructor(public name: string, public firstName: string,
public companyName: string){
}
public save(name: string,firstName: string) : string {
Employee.totalNumberOfEmployeeSaved += 1;
return this.name + ' '+ firstName + 'just saved ';
}
static totalNumberOfEmployeeSaved: number = 0;
}
18 of 38
TypeScript Fundamentals
var emp = new Employee('Haeck','Ruben','Queaso Systems');
emp.save('Wayne','Bruce');
// returns 'Haeck Bruce just saved'
19 of 38
TypeScript Fundamentals
• Access modifiers
– Public, private and protected
class Car {
public price: number;
private priceeWithVAT: number;
}
20 of 38
TypeScript Fundamentals
• Interface implementation
• Class inheritance
class Car implements ICar {
…
}
class SecretCar extends Car {
constructor(name: string, power: number, alias: string){
super(name, power);
}
}
21 of 38
From AngularJS to Angular
22 of 38
TypeScript
• Heel veel info
– https://www.typescriptlang.org/
23 of 38
Angular
• Sneller/Performant
• Eenvoudiger
• Response webdesign
24 of 38
Releases
2010
• Initiële (instabiele) release (0.9.0)
2012
• Release 1.1
• Initiële versie TypeScript (0.8.0)
2013
• Release 1.2 → Drop support IE6 & IE7
2014
• Release 1.3 → Drop support IE8
• Release TypeScript 1.1
25 of 38
Releases
07/2016
• Release 1.5.8 → Introductie “components”
09/2016
• Release 2.0 → “Angular”
• Release TypeScript 2.0 → introductie “@types/…”
2017
• Release 4
• Release 5
2018
• Release 6
• Release 7
26 of 38
Languages
• EcmaScript 5
• EcmaScript 6 (2015)
• TypeScript
• Dart
compile
types
JavaScript
27 of 38
Modules
AngularJS (JS) Angular (TS)
(function(){
// add third party libs
angular.module(‘app’,[]);
})();
<div ng-app=“app”>
…
</div>
import { BrowserModule } from '@angular/platform-
browser';
import { NgModule } from '@angular/core';
@NgModule({
imports: [
BrowserModule],
providers: […],
bootstrap: […]
})
export class AppModule { }
28 of 38
Controllers →
AngularJS (TS) Angular (TS)
class CompanyController {
name: string = ‘Queaso Systems’;
constructor() { }
}
angular.module(‘app’)
.controller(‘CompanyController’,
CompanyController);
<div ng-
controller=“CompanyController as
vm”>
{{ vm.name }}
</div>
import { BrowserModule } from '@angular/platform-
browser';
import { NgModule } from '@angular/core';
@Component({
selector: ‘company-card’,
template: ‘<h1>{{ company.name }}</h1>’
})
export class CompanyComponent {
company = { name: ‘Queaso Systems’, id: 1 };
}
<company-card></company-card>
Components
29 of 38
Built-in directives
AngularJS (HTML) Angular (HTML)
<table>
<tr ng-repeat=“e in
vm.employees” >
<td>{{ e.name }}</td>
</table>
<div ng-show=“vm.isEU”>
Is part of the EU!
</div>
<table>
<tr *ngFor=“e of employees”>
<td>{{ e.name }}</td>
</tr>
</table>
<div *ngIf=“isEU”>
Is part of the EU!
</div>
30 of 38
1 Way Binding
AngularJS (HTML) Angular (HTML)
<h1 ng-bind=“vm.company.name”>
</h1>
<h1 [innerText]=“company.name”></h1>
31 of 38
Event Binding
AngularJS (HTML) Angular (HTML)
<input type=“button”
ng-click=“vm.showDetail()”
value=“OK” />
<input type=“button”
(click)=“showDetail()”
value=“OK’ />
32 of 38
2 Way Binding
AngularJS (HTML) Angular (HTML)
<input type=“button”
ng-model=“vm.company.name”
/>
<input type=“button”
[(ngModel)]=“company.name”
/>
33 of 38
Services
registraties
AngularJS (TS) Angular (TS)
export class QueasoService {
constructor() { }
countEmployees(): number {
return 25;
}
}
angular.module(‘app’)
.service(‘QService’,
QueasoService);
@Injectable()
export class QueasoService {
countEmployees(): number {
return 25;
}
}
34 of 38
Services
resolving
AngularJS (TS) Angular (TS)
class AppController {
static $inject = [‘QService’];
constructor(queasoService:
QueasoService){
let x = queasoService
.countEmployees();
}
}
@Component({ … })
class AppComponent {
constructor(queasoService: QueasoService) {
let x = queasoService.countEmployees();
}
}
35 of 38
Promise vs Observable
• Promise
– 1 value
– Not Cancelable
– Geen utility methodes
• Observable
– Superset van promises
– Meerdere values
– Cancelable
– Utility methods
• Streams
36 of 38
Services
Http
AngularJS (TS) Angular (TS)
class QueasoDataService {
baseUrl = 'http://api.queaso.be
';
static $inject = ['$http'];
constructor(private $http: ang
ular.IHttpService){
}
getEmployees(): angular.IHttpP
romise<Array<Employee>> {
return this.$http
.get(this.baseUrl + '/employees'
);
}
}
Import { Http, Response } from ‘@angular/http’
@Injectable()
class QueasoDataService {
baseUrl = 'http://api.queaso.be';
constructor(http: Http) { }
getEmployees(): Observable<Array<Employee>> {
return this.http.get(this.baseUrl)
.map((result: Response) => result.json())
.catch((error: any) => Observable.throw(…));
}
}
37 of 38
Services
Http
AngularJS (TS) Angular (TS)
class AppController {
employees: Array<Employee>;
static $inject = ['
QueasoDataService'];
constructor(private qService:
QueasoDataService){
qService.getEmployees().then(
(result: any) => {
employees = result.data
});
}
}
class AppComponent {
employees: Array<Employee>;
constructor(qService: QueasoDataService) {
qService.getEmployees().subscribe(
x => this.employees,
error => {
console.log(error);
});
}
}
38 of 38
• Demo
– angular-cli
– Spotify api

More Related Content

What's hot (7)

PDF
Pharo Optimising JIT Internals
ESUG
 
PDF
Philip Shurpik "Architecting React Native app"
Fwdays
 
PDF
Borland star team to tfs simple migration
Shreesha Rao
 
PDF
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
Luciano Mammino
 
PDF
Commit University - Exploring Angular 2
Commit University
 
PDF
Express: A Jump-Start
Naveen Pete
 
PDF
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Ontico
 
Pharo Optimising JIT Internals
ESUG
 
Philip Shurpik "Architecting React Native app"
Fwdays
 
Borland star team to tfs simple migration
Shreesha Rao
 
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
Luciano Mammino
 
Commit University - Exploring Angular 2
Commit University
 
Express: A Jump-Start
Naveen Pete
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Ontico
 

Viewers also liked (18)

PPT
TypeScript Presentation
Patrick John Pacaña
 
PDF
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
PDF
Angular 2 - Core Concepts
Fabio Biondi
 
PDF
Développement web mobile avec IONIC 2
Jean David Olekhnovitch
 
PDF
1.1.7 Система огнестойких проходок Vulcan
Igor Golovin
 
DOCX
oyene safety cv
oyene zacharias abiranyah
 
PPTX
Betaleadership De Gestores de Recursos Humanos a Makers de Interacciones Humanas
Sylvain Loubradou
 
PPTX
Miten markkinoinnin automaation käyttöönotto aloitti tekijöitään suuremman mu...
Tarja Röytiö
 
PDF
Brochure eventos Spiwak
Hotel Stancia Spiwak
 
PDF
1.1.9 Система Angara и дренажные трубы
Igor Golovin
 
PDF
Auto del Tribunal Supremo. Sala Cuarta.
Juan Segura Aguiló
 
PPT
Active Procrastination
Nupur_Deshpande
 
PPTX
Baby's First Open Source Project
Julien Fitzpatrick
 
PDF
برنامج مقترح لتعلم (تعلم الآلة)
Fares Al-Qunaieer
 
PDF
Cloud Security Alliance Japan Chapter Big Data User Working Group 2014 action...
Eiji Sasahara, Ph.D., MBA 笹原英司
 
PDF
Fotosíntesis del futuro
Merelyn Valdivia
 
PPT
Le sourire au naturel. Métamorphoses du portrait photographique
André Gunthert
 
PDF
ارقام شركات مكافحة الحشرات بمكة رش مبيديات النمل الابيض الاسود الصراصير بق ال...
o2adv تسويق وارشفة مسك كلمات بجوجل
 
TypeScript Presentation
Patrick John Pacaña
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
Angular 2 - Core Concepts
Fabio Biondi
 
Développement web mobile avec IONIC 2
Jean David Olekhnovitch
 
1.1.7 Система огнестойких проходок Vulcan
Igor Golovin
 
oyene safety cv
oyene zacharias abiranyah
 
Betaleadership De Gestores de Recursos Humanos a Makers de Interacciones Humanas
Sylvain Loubradou
 
Miten markkinoinnin automaation käyttöönotto aloitti tekijöitään suuremman mu...
Tarja Röytiö
 
Brochure eventos Spiwak
Hotel Stancia Spiwak
 
1.1.9 Система Angara и дренажные трубы
Igor Golovin
 
Auto del Tribunal Supremo. Sala Cuarta.
Juan Segura Aguiló
 
Active Procrastination
Nupur_Deshpande
 
Baby's First Open Source Project
Julien Fitzpatrick
 
برنامج مقترح لتعلم (تعلم الآلة)
Fares Al-Qunaieer
 
Cloud Security Alliance Japan Chapter Big Data User Working Group 2014 action...
Eiji Sasahara, Ph.D., MBA 笹原英司
 
Fotosíntesis del futuro
Merelyn Valdivia
 
Le sourire au naturel. Métamorphoses du portrait photographique
André Gunthert
 
ارقام شركات مكافحة الحشرات بمكة رش مبيديات النمل الابيض الاسود الصراصير بق ال...
o2adv تسويق وارشفة مسك كلمات بجوجل
 
Ad

Similar to Get together on getting more out of typescript &amp; angular 2 (20)

PDF
AngularJS for Web and Mobile
Rocket Software
 
PDF
Angular 2 overview in 60 minutes
Loiane Groner
 
PPTX
Getting Started with Angular JS
Akshay Mathur
 
PPTX
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
PPTX
Basics of AngularJS
Filip Janevski
 
PDF
Download full ebook of Angularjs Brad Green Shyam Seshadri instant download pdf
mehiicniode
 
PDF
Angular js quickstart
LinkMe Srl
 
PDF
Migrating to Angular 5 for Spring Developers
Gunnar Hillert
 
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
PDF
Migrating to Angular 4 for Spring Developers
VMware Tanzu
 
PDF
Angular JS2 Training Session #1
Paras Mendiratta
 
PDF
Dmytro Kochergin Angular 2 and New Java Script Technologies
LogeekNightUkraine
 
PPSX
Angular js
Arun Somu Panneerselvam
 
PDF
An introduction to Angular2
Apptension
 
PDF
Angular training-course-syllabus
Training Institute
 
PPTX
Fly High With Angular - How to build an app using Angular
Vacation Labs
 
PDF
AngularJS Curriculum-Zeolearn
Hamdi Ceylan
 
PDF
Type Script Conceitos de ts para projetos front-end React - por ruben marcus
Ruben Marcus Luz Paschoarelli
 
PPTX
Angular Data Binding
Jennifer Estrada
 
PDF
Testdrive AngularJS with Spring 4
Oliver Wahlen
 
AngularJS for Web and Mobile
Rocket Software
 
Angular 2 overview in 60 minutes
Loiane Groner
 
Getting Started with Angular JS
Akshay Mathur
 
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
Basics of AngularJS
Filip Janevski
 
Download full ebook of Angularjs Brad Green Shyam Seshadri instant download pdf
mehiicniode
 
Angular js quickstart
LinkMe Srl
 
Migrating to Angular 5 for Spring Developers
Gunnar Hillert
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
Migrating to Angular 4 for Spring Developers
VMware Tanzu
 
Angular JS2 Training Session #1
Paras Mendiratta
 
Dmytro Kochergin Angular 2 and New Java Script Technologies
LogeekNightUkraine
 
An introduction to Angular2
Apptension
 
Angular training-course-syllabus
Training Institute
 
Fly High With Angular - How to build an app using Angular
Vacation Labs
 
AngularJS Curriculum-Zeolearn
Hamdi Ceylan
 
Type Script Conceitos de ts para projetos front-end React - por ruben marcus
Ruben Marcus Luz Paschoarelli
 
Angular Data Binding
Jennifer Estrada
 
Testdrive AngularJS with Spring 4
Oliver Wahlen
 
Ad

Recently uploaded (20)

PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 

Get together on getting more out of typescript &amp; angular 2

  • 1. 1 of 38 GetTogether Getting more out of TypeScript and Angular 2 Ruben Haeck 28/03/2017
  • 2. 2 of 38 Agenda • Intro • TypeScript • From AngularJS to Angular • Demo
  • 3. 3 of 38 Intro • Ruben Haeck – Queaso Systems NV – 11 jaar ervaring – [email protected]
  • 4. 4 of 38 Tools • Visual Studio 2015/2017 – Belangrijk: Web Essentials • o.a compilatie → TypeScipt, LESS, … • Visual Studio Code (1.10.2) • WebStorm • Google Chrome • Pluncker → https://plnkr.co
  • 6. 6 of 38 TypeScript • Meta language → JavaScript • Compileert → JavaScript • By Microsoft, open source • Uitbreiding JavaScript – Strongly typed class-based environment • http://www.typescriptlang.org
  • 9. 9 of 38 Voordelen • Handige → Large-scale JS applications • Volgt de ECMAScript 6 standaard • IDE ondersteuning – Intellisense • Compile-time type checking
  • 10. 10 of 38 Compile • NodeJS • Visual Studio 2015 – Plugin for TypeScript – Web Essentials extension • Andere – TypeScript gecompileerd door TypeScript • Client side by SystemJS npm install –g typescript tsc basics.ts tsc basics.ts
  • 11. 11 of 38 TypeScript Fundamentals • Basic types • Variables • Functions – Declaration, overloading • Interfaces • Classes – Constructors, Implemenation, Inheritance
  • 12. 12 of 38 TypeScript Fundamentals • Generics • Enums • Namespaces • Modules
  • 13. 13 of 38 TypeScript Fundamentals • Basic types – any • Supertype of all types • Als type niet is gekend → any – Primitieve types •number, string, boolean • Opgelet: Object → interface!
  • 14. 14 of 38 • Array types • Object type • Void type – Enkel als return type → functie TypeScript Fundamentals var names: string[] var names: Array<string> var car: { name: string, company: string}; car = { name: ‘BMW’, company: ‘Queaso Systems’} function logMe(text: string) : void { console.log(text); }
  • 15. 15 of 38 TypeScript Fundamentals • Interfaces interface IPerson { name: string; } interface IQueasoEmployee extends IPerson { happy: boolean; age: number; savePerson(person: IPerson): void; } multiple inheritance
  • 16. 16 of 38 TypeScript Fundamentals • Classes – Instance members – Static members – Access modifiers – Constructors – Interface implementation – Class inheritance
  • 17. 17 of 38 TypeScript Fundamentals class Employee { // # constructor(s) constructor(public name: string, public firstName: string, public companyName: string){ } public save(name: string,firstName: string) : string { Employee.totalNumberOfEmployeeSaved += 1; return this.name + ' '+ firstName + 'just saved '; } static totalNumberOfEmployeeSaved: number = 0; }
  • 18. 18 of 38 TypeScript Fundamentals var emp = new Employee('Haeck','Ruben','Queaso Systems'); emp.save('Wayne','Bruce'); // returns 'Haeck Bruce just saved'
  • 19. 19 of 38 TypeScript Fundamentals • Access modifiers – Public, private and protected class Car { public price: number; private priceeWithVAT: number; }
  • 20. 20 of 38 TypeScript Fundamentals • Interface implementation • Class inheritance class Car implements ICar { … } class SecretCar extends Car { constructor(name: string, power: number, alias: string){ super(name, power); } }
  • 21. 21 of 38 From AngularJS to Angular
  • 22. 22 of 38 TypeScript • Heel veel info – https://www.typescriptlang.org/
  • 23. 23 of 38 Angular • Sneller/Performant • Eenvoudiger • Response webdesign
  • 24. 24 of 38 Releases 2010 • Initiële (instabiele) release (0.9.0) 2012 • Release 1.1 • Initiële versie TypeScript (0.8.0) 2013 • Release 1.2 → Drop support IE6 & IE7 2014 • Release 1.3 → Drop support IE8 • Release TypeScript 1.1
  • 25. 25 of 38 Releases 07/2016 • Release 1.5.8 → Introductie “components” 09/2016 • Release 2.0 → “Angular” • Release TypeScript 2.0 → introductie “@types/…” 2017 • Release 4 • Release 5 2018 • Release 6 • Release 7
  • 26. 26 of 38 Languages • EcmaScript 5 • EcmaScript 6 (2015) • TypeScript • Dart compile types JavaScript
  • 27. 27 of 38 Modules AngularJS (JS) Angular (TS) (function(){ // add third party libs angular.module(‘app’,[]); })(); <div ng-app=“app”> … </div> import { BrowserModule } from '@angular/platform- browser'; import { NgModule } from '@angular/core'; @NgModule({ imports: [ BrowserModule], providers: […], bootstrap: […] }) export class AppModule { }
  • 28. 28 of 38 Controllers → AngularJS (TS) Angular (TS) class CompanyController { name: string = ‘Queaso Systems’; constructor() { } } angular.module(‘app’) .controller(‘CompanyController’, CompanyController); <div ng- controller=“CompanyController as vm”> {{ vm.name }} </div> import { BrowserModule } from '@angular/platform- browser'; import { NgModule } from '@angular/core'; @Component({ selector: ‘company-card’, template: ‘<h1>{{ company.name }}</h1>’ }) export class CompanyComponent { company = { name: ‘Queaso Systems’, id: 1 }; } <company-card></company-card> Components
  • 29. 29 of 38 Built-in directives AngularJS (HTML) Angular (HTML) <table> <tr ng-repeat=“e in vm.employees” > <td>{{ e.name }}</td> </table> <div ng-show=“vm.isEU”> Is part of the EU! </div> <table> <tr *ngFor=“e of employees”> <td>{{ e.name }}</td> </tr> </table> <div *ngIf=“isEU”> Is part of the EU! </div>
  • 30. 30 of 38 1 Way Binding AngularJS (HTML) Angular (HTML) <h1 ng-bind=“vm.company.name”> </h1> <h1 [innerText]=“company.name”></h1>
  • 31. 31 of 38 Event Binding AngularJS (HTML) Angular (HTML) <input type=“button” ng-click=“vm.showDetail()” value=“OK” /> <input type=“button” (click)=“showDetail()” value=“OK’ />
  • 32. 32 of 38 2 Way Binding AngularJS (HTML) Angular (HTML) <input type=“button” ng-model=“vm.company.name” /> <input type=“button” [(ngModel)]=“company.name” />
  • 33. 33 of 38 Services registraties AngularJS (TS) Angular (TS) export class QueasoService { constructor() { } countEmployees(): number { return 25; } } angular.module(‘app’) .service(‘QService’, QueasoService); @Injectable() export class QueasoService { countEmployees(): number { return 25; } }
  • 34. 34 of 38 Services resolving AngularJS (TS) Angular (TS) class AppController { static $inject = [‘QService’]; constructor(queasoService: QueasoService){ let x = queasoService .countEmployees(); } } @Component({ … }) class AppComponent { constructor(queasoService: QueasoService) { let x = queasoService.countEmployees(); } }
  • 35. 35 of 38 Promise vs Observable • Promise – 1 value – Not Cancelable – Geen utility methodes • Observable – Superset van promises – Meerdere values – Cancelable – Utility methods • Streams
  • 36. 36 of 38 Services Http AngularJS (TS) Angular (TS) class QueasoDataService { baseUrl = 'http://api.queaso.be '; static $inject = ['$http']; constructor(private $http: ang ular.IHttpService){ } getEmployees(): angular.IHttpP romise<Array<Employee>> { return this.$http .get(this.baseUrl + '/employees' ); } } Import { Http, Response } from ‘@angular/http’ @Injectable() class QueasoDataService { baseUrl = 'http://api.queaso.be'; constructor(http: Http) { } getEmployees(): Observable<Array<Employee>> { return this.http.get(this.baseUrl) .map((result: Response) => result.json()) .catch((error: any) => Observable.throw(…)); } }
  • 37. 37 of 38 Services Http AngularJS (TS) Angular (TS) class AppController { employees: Array<Employee>; static $inject = [' QueasoDataService']; constructor(private qService: QueasoDataService){ qService.getEmployees().then( (result: any) => { employees = result.data }); } } class AppComponent { employees: Array<Employee>; constructor(qService: QueasoDataService) { qService.getEmployees().subscribe( x => this.employees, error => { console.log(error); }); } }
  • 38. 38 of 38 • Demo – angular-cli – Spotify api