Slide 1

Slide 1 text

Angular 4
 component model Robert Wurm www.easysolutions.io

Slide 2

Slide 2 text

WARNING By the end of this presentation you 
 won´t become an Angular expert, but you´ll start being dangerous!

Slide 3

Slide 3 text

What is 
 Angular

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

core (zones, di, abstractions, etc.) renderer http compiler forms router i18n ngUpgrade animations CLI material 2 testing language
 services Universal angularfire2 One Framework

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

A Brief Chronology AngularJS Angular 2 Angular 3 Angular (4) - Modularity - Introduced Microsoft´s TypeScript language - Improved dependency injection - Simple routing - AoT compiling - Mobile development - Modern browser only - …. - Performance boost - Stand alone animation module - More syntax in HTML templates 
 (if … else)

Slide 8

Slide 8 text

Angular´s Core

Slide 9

Slide 9 text

Component ng generate component HelloWorld src/app/hello-world/ hello-world.component.css hello-world.component.html hello-world.component.spec.ts hello-world.component.ts

Slide 10

Slide 10 text

Basic Component import { Component } from '@angular/core'; @Component({ selector: 'my-hello-world', templateUrl: './hello-world.component.html', styleUrls: ['./hello-world.component.scss'] }) export class HelloWorldComponent { }

Slide 11

Slide 11 text

Binding import { Component } from '@angular/core'; @Component({ selector: 'my-hello-world', styleUrls: ['./hello-world.component.scss'], template: `

{{ title }}

Green ` }) export class HelloWorldComponent { title: string = 'Hello World!'; color: string = 'red'; changeColor(color: string) { this.color = color; } }

Slide 12

Slide 12 text

Component Lifecycle import { Component } from '@angular/core'; import { SampleService } from '../services/sample.service.ts'; @Component({ selector: 'my-hello-world', templateUrl: './hello-world.component.html', styleUrls: ['./hello-world.component.scss'] }) export class HelloWorldComponent { constructor(private sampleService: SampleService) { // do simple stuff } } constructor

Slide 13

Slide 13 text

Component Lifecycle onInit import { Component, OnInit } from '@angular/core'; import { SampleService } from '../services/sample.service.ts'; @Component({ selector: 'my-hello-world', templateUrl: './hello-world.component.html', styleUrls: ['./hello-world.component.scss'] }) export class HelloWorldComponent implements OnInit { constructor(private sampleService: SampleService) { // do simple stuff } ngOnInit() { // do elaborate stuff this.samples = this.sampleService.getSamples(); } }

Slide 14

Slide 14 text

// Pseudo Code import { Component, OnInit, ... } from '@angular/core'; @Component({ ... }) export class HelloWorldComponent implements OnInit, ... { ngOnInit() {} ngOnChanges(changes) {} ngDoCheck() {} ngOnDestroy() {} ngAfterContentInit() {} ngAfterContentChecked() {} ngAfterViewInit() {} ngAfterViewChecked() {} } More component lifecycle hooks

Slide 15

Slide 15 text

Architecture

Slide 16

Slide 16 text

Component-Tree sidebar app-root parent header hello-world hello-world

Slide 17

Slide 17 text

Communication

Slide 18

Slide 18 text

Example with Panel title=“Hello Stahlstadt” Hello Stahlstadt onExpand

Slide 19

Slide 19 text

import { Component, Input, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'my-panel', styleUrls: ['./panel.component.scss'], template: `

{{ title }}

` }) export class PanelComponent { @Input title: string; @Output onExpand = new EventEmitter(); onExpandBtnClicked() { this.onExpand.emit(); } }

Slide 20

Slide 20 text

Hello StahlstadtJS Hello StahlstadtTS

Slide 21

Slide 21 text

Routing ../hello ../panel

Slide 22

Slide 22 text

Routing import { ParentComponent } from './components/parent/parent.component'; import { HelloWorldComponent } from './components/hello-world/hello-world.component'; import { PanelComponent } from './components/panel/panel.component'; import { ModuleWithProviders } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; const appRoutes: Routes = [ path: 'parent', component: ParentComponent, children: [ { path: 'hello', component: HelloWorldComponent, }, { path: 'panel', component: PanelComponent, } ] } ]; export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

Slide 23

Slide 23 text

Looks great
 BUT

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Modules ng generate module HelloWorld HelloWorldModule Component1 Component 2 Component … Import Export routing

Slide 26

Slide 26 text

Basic Module import { routing } from './hello-world.routing'; import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; @NgModule({ imports: [ CommonModule, routing ], declarations: [ HelloWorldComponent, Component1 ], exports: [ HelloWorldComponent ] }) export class HelloWorldModule { }

Slide 27

Slide 27 text

Component-Tree component1 app-module module1 component2

Slide 28

Slide 28 text

Routing import { Routes, RouterModule } from '@angular/router'; const appRoutes: Routes = [ { path: 'foo', component: Component1 }, { path: 'hello', loadChildren: './components/hello-world/hello-world.module' } ]; export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

Slide 29

Slide 29 text

Single Page Application
 SPA Client Server Initial Request AJAX JSON { .. } Bundle.js ng build --env=prod

Slide 30

Slide 30 text

Lazy Loading import { Routes, RouterModule } from '@angular/router'; const appRoutes: Routes = [ { path: 'foo', component: Component1 }, { path: 'hello', loadChildren: './components/hello-world/hello- world.module#HelloWorldModule' } ]; export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

Slide 31

Slide 31 text

Client Server Initial Request AJAX JSON { .. } Bundle0.js Lazy Loading Bundle1.js ../hello

Slide 32

Slide 32 text

Demo Robert Wurm

Slide 33

Slide 33 text

Question, please? Robert Wurm [email protected]