jan 2017 - a web of applications (angular 2)

51
a web of applications kasper reijnders

Upload: kasper-reijnders

Post on 12-Apr-2017

52 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Jan 2017 - a web of applications (angular 2)

a web of applicationskasper reijnders

Page 2: Jan 2017 - a web of applications (angular 2)

01 introduction tijd (minuten) 1-3

02 why this subject tijd (minuten) 5-10

03 summarize tijd (minuten) 2-5

04 angular tijd (minuten) 10-20

tonight

Page 3: Jan 2017 - a web of applications (angular 2)

introductionKasper Reijnders○fronteer

○scout

○incentronaut

Page 4: Jan 2017 - a web of applications (angular 2)

why this subject

Page 5: Jan 2017 - a web of applications (angular 2)
Page 6: Jan 2017 - a web of applications (angular 2)
Page 7: Jan 2017 - a web of applications (angular 2)
Page 8: Jan 2017 - a web of applications (angular 2)
Page 9: Jan 2017 - a web of applications (angular 2)
Page 10: Jan 2017 - a web of applications (angular 2)
Page 11: Jan 2017 - a web of applications (angular 2)
Page 12: Jan 2017 - a web of applications (angular 2)
Page 13: Jan 2017 - a web of applications (angular 2)

website○using CMS○basic frontend functionality

○lightbox○search○sharing○etc…

○knmg.nl / incentro.com

Page 14: Jan 2017 - a web of applications (angular 2)

web apps○using content from some repository○single page applications○advanced frontend

○multiple components○facebook.com / twitter.com / airbnb.com

Page 15: Jan 2017 - a web of applications (angular 2)

combined○apps integrated in site

○ used for ‘difficult’ content / calculations / checks

○anwb.nl / unive.nl / snsbank.nl

Page 16: Jan 2017 - a web of applications (angular 2)

angular

Page 17: Jan 2017 - a web of applications (angular 2)

angular○web apps

○ integrated web apps

Page 18: Jan 2017 - a web of applications (angular 2)

angular○version 1.x ○version 2.x and above

○next version will be 4.x

Page 19: Jan 2017 - a web of applications (angular 2)

angular > 2.x○Modular

○components and services○TypeScript○Annotations

Page 20: Jan 2017 - a web of applications (angular 2)
Page 21: Jan 2017 - a web of applications (angular 2)
Page 22: Jan 2017 - a web of applications (angular 2)

typescript

import {Goal} from "../types/goal";

export class ThemeService {

private goal: Goal;

constructor() { }}

export class Goal { title: string; status: Array<number> | boolean; planned?: boolean;}

Page 23: Jan 2017 - a web of applications (angular 2)

typescript / es6

function test(i) { return i + 2;}

let test = i => i + 2

Page 24: Jan 2017 - a web of applications (angular 2)

codecomponents

ngmodule

input and output

services

pipes

directives

templates

Page 25: Jan 2017 - a web of applications (angular 2)

componentimport { Component } from '@angular/core';

@Component({ selector: 'batman', template: '<h1>{{name}}</h1>'})export class BatmanComponent { name: string = 'Batman'; hasParents: boolean = false;}

Page 26: Jan 2017 - a web of applications (angular 2)

componentimport { Component } from '@angular/core';

@Component({ selector: 'batman', template: '<h1>{{name}}</h1>'})export class BatmanComponent { name: string = 'Batman'; hasParents: boolean = false;}

Page 27: Jan 2017 - a web of applications (angular 2)

componentimport { Component } from '@angular/core';

@Component({ selector: 'batman', template: '<h1>{{name}}</h1>'})export class BatmanComponent { name: string = 'Batman'; hasParents: boolean = false;}

Page 28: Jan 2017 - a web of applications (angular 2)

componentimport { Component } from '@angular/core';

@Component({ selector: 'batman', template: '<h1>{{name}}</h1>'})export class BatmanComponent { name: string = 'Batman'; hasParents: boolean = false;}

Page 29: Jan 2017 - a web of applications (angular 2)

moduleimport { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BatmanComponent } from './batman.component';

@NgModule({ imports: [ BrowserModule ], declarations: [ BatmanComponent ], bootstrap: [ BatmanComponent ]})export class EverythingIsAwesomeApp { }

Page 30: Jan 2017 - a web of applications (angular 2)

moduleimport { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BatmanComponent } from './batman.component';

@NgModule({ imports: [ BrowserModule ], declarations: [ BatmanComponent ], bootstrap: [ BatmanComponent ]})export class EverythingIsAwesomeApp { }

Page 31: Jan 2017 - a web of applications (angular 2)

moduleimport { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BatmanComponent } from './batman.component';

@NgModule({ imports: [ BrowserModule ], declarations: [ BatmanComponent ], bootstrap: [ BatmanComponent ]})export class EverythingIsAwesomeApp { }

Page 32: Jan 2017 - a web of applications (angular 2)

moduleimport { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BatmanComponent } from './batman.component';

@NgModule({ imports: [ BrowserModule ], declarations: [ BatmanComponent ], bootstrap: [ BatmanComponent ]})export class EverythingIsAwesomeApp { }

Page 33: Jan 2017 - a web of applications (angular 2)

moduleimport { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BatmanComponent } from './batman.component';

@NgModule({ imports: [ BrowserModule ], declarations: [ BatmanComponent ], bootstrap: [ BatmanComponent ]})export class EverythingIsAwesomeApp { }

Page 34: Jan 2017 - a web of applications (angular 2)

moduleimport { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BatmanComponent } from './batman.component';import { BatMobileComponent } from './batmobile.component';

@NgModule({ imports: [ BrowserModule ], declarations: [ BatmanComponent, BatMobileComponent ], bootstrap: [ BatmanComponent ]})export class EverythingIsAwesomeApp { }

Page 35: Jan 2017 - a web of applications (angular 2)

input and outputimport { Component, Input } from '@angular/core';

@Component({ selector: 'batmobile', template: '<div>{{driver}}</div>'})export class BatMobileComponent { @Input() driver: string;}

Page 36: Jan 2017 - a web of applications (angular 2)

input and outputimport { Component } from '@angular/core';

@Component({ selector: 'batman', template: '<batmobile [driver]="name"></batmobile>'})export class BatmanComponent { name: string = 'Batman'; hasParents: boolean = false;}

Page 37: Jan 2017 - a web of applications (angular 2)

servicesimport { Injectable } from '@angular/core';import { Car } from 'car';import { CARS } from 'CARS.MOCK';

@Injectable()export class BatmobileService { constructor() {}

getCarPark(): Promise<Car[]> { return Promise.resolve(CARS); // this can be replaced with a REST call }

getCarByDriver(driver: string): Promise<Car> { return this.getCarPark().then((cars) => { return cars.find(car => car.driver === driver); }); }}

Page 38: Jan 2017 - a web of applications (angular 2)

servicesimport { Component, Input } from '@angular/core';

@Component({ selector: 'batmobile', template: '<div>{{driver}}</div>'})export class BatMobileComponent { @Input() driver: string;}

Page 39: Jan 2017 - a web of applications (angular 2)

servicesimport { Component, Input, OnInit } from '@angular/core';import { BatmobileService } from 'batmobileservice';

@Component({ selector: 'batmobile', template: '<div>{{driver}}</div>'})export class BatMobileComponent implements ngOnInit { @Input() driver: string;

constructor(private batmobileService: BatmobileService) {}

ngOnInit() { // ... }}

Page 40: Jan 2017 - a web of applications (angular 2)

services...

constructor(private batmobileService: BatmobileService) {}

ngOnInit() { this.batmobileService.getCarByDriver(this.driver).then((car) => {

this.car = car });

}

...

Page 41: Jan 2017 - a web of applications (angular 2)

pipes

{{ someValue | pipe }}

{{ birthday | date:'fullDate' | uppercase }}

{{ users | filter: 'name' }}

Page 42: Jan 2017 - a web of applications (angular 2)

directives

1. Components

2. Structural directives

3. Attribute directives

Page 43: Jan 2017 - a web of applications (angular 2)

structural directives

*ngFor

*ngIf

[ngSwitch]

*ngSwitchCase

*ngSwitchDefault

Page 44: Jan 2017 - a web of applications (angular 2)

asterisk

<p *ngIf="condition">Our heroes are true!</p>

<template [ngIf]="condition">

<p>Our heroes are true!</p>

</template>

Page 45: Jan 2017 - a web of applications (angular 2)

attribute directives

<div [style.background]="'lime'"> some </div>

<p myHighlight [highlightColor]="color"> color</p>

<p [myHighlight]="color">Highlight me!</p>

Page 46: Jan 2017 - a web of applications (angular 2)

template options<input [value]="firstName"> Binds property value to the result of expression

firstName.

<div [attr.role]="myAriaRole"> Binds attribute role to the result of expression myAriaRole.

<div [class.extra-

sparkle]="isDelightful">

Binds the presence of the CSS class extra-sparkle on the element to the truthiness of the expression isDelightful.

<div [style.width.px]="mySize"> Binds style property width to the result of expression mySize in pixels. Units are optional.

<button (click)="readRainbow($event)"> Calls method readRainbow when a click event is triggered on this button element (or its children) and passes in the event object.

<my-cmp [(title)]="name"> Sets up two-way data binding. Equivalent to: <my-cmp [title]="name" (titleChange)="name=$event">

Page 47: Jan 2017 - a web of applications (angular 2)

<p>Card No.: {{cardNumber | myCardNumberFormatter}}</p> Transforms the current value of expression cardNumber

via the pipe called myCardNumberFormatter.

<p>Employer: {{employer?.companyName}}</p> The safe navigation operator (?) means that the

employer field is optional and if undefined, the rest of the expression should be ignored.

<p>Hello {{superHero}}</p> Binds text content to an interpolated string, for example, "Hello Seabiscuit".

template options

Page 48: Jan 2017 - a web of applications (angular 2)

angularjscomponents

ngmodule

input and output

services

pipes

directives

templates

Page 49: Jan 2017 - a web of applications (angular 2)

tipsuse angular-cli to jumpstart development -> https://cli.angular.io/

have 1 functionality per file

divide data and function

make reusable components

Page 50: Jan 2017 - a web of applications (angular 2)

use folders per type- batman-project/

- src/scripts/- components/- directives/- services/- types/- main.ts

Page 51: Jan 2017 - a web of applications (angular 2)