Top Banner
1 The new Component Router for Angular 2 and 1.x Manfred Steyer ManfredSteyer Current Book Folie 2 O'Reilly: AngularJS: Moderne Webanwendungen und Single Page Applications mit JavaScript Steyer, Softic
15

The new component router for Angular 2 and 1.x

Apr 12, 2017

Download

Internet

Manfred Steyer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The new component router for Angular 2 and 1.x

1

The new Component Router for Angular 2 and 1.x

Manfred Steyer

ManfredSteyer

Current Book

Folie 2

O'Reilly:

AngularJS: Moderne

Webanwendungen und Single Page

Applications mit JavaScript

Steyer, Softic

Page 2: The new component router for Angular 2 and 1.x

2

Contents

Overview of Concepts and Scenarios

Getting started

DEMO with Angular 2

Lifecycle-Hooks

DEMO with Angular 2

DEMO with Angular 1.x

Aux-Routes

Page 3

OVERVIEW

Page 4

Page 3: The new component router for Angular 2 and 1.x

3

What is the Component Router?

Page 5

New Router-Solution

Angular 2 and 1.x

ActivatingComponents

LazyLoading

HierarchicalRouting

Lifecycle-Hooks

Routing

Page 6

Logo + Menu

Men

u 2

Footer

SPAPlaceholder

Page 4: The new component router for Angular 2 and 1.x

4

Routing

Page 7

Logo + Menü

Men

ü 2

Fußzeile

SPAFlight

-Component

/FlightApp#/flights

Routing with History API

Page 8

Logo + Menü

Men

ü 2

Fußzeile

SPAFlight

-Component

/FlightApp/flights

Page 5: The new component router for Angular 2 and 1.x

5

Routing with Parameter

Page 9

Logo + Menü

Men

ü 2

Fußzeile

SPAFlight-Edit-

Component

for Flight #17

/FlightApp/flights/17

Hierarchical Routing

Page 11

Logo + Menu

Men

u 2

Footer

SPA

Placeholder

Page 6: The new component router for Angular 2 and 1.x

6

Hierarchical Routing

Page 12

Logo + Menu

Men

u 2

Footer

SPA

/FlightApp/flight-bookingF

ligh

tBo

okin

g-C

om

po

ne

nt

Hierarchical Routing

Page 13

Logo + Menu

Men

u 2

Footer

SPA

/FlightApp/flight-booking

Options

Placeholder

Flig

htB

oo

kin

g-C

om

po

ne

nt

+ Child-Router

Page 7: The new component router for Angular 2 and 1.x

7

Hierarchical Routing

Page 14

Logo + Menu

Men

u 2

Fußzeile

SPA

/FlightApp/flight-booking/flights

Optionen

Flight-

Component

Flig

htB

oo

kin

g-C

om

po

ne

nt

GETTING STARTED

Page 15

Page 8: The new component router for Angular 2 and 1.x

8

Getting started

Page 16

Bundle: router.js ROUTER_PROVIDERS

ROUTER_DIRECTIVES

Getting started

Hash-Strategy

provide(LocationStrategy,

{useClass: HashLocationStrategy})

Path-Strategy (History API)

Default

Base-Url via <base href="…"> or APP_BASE_HREF

Page 17

Page 9: The new component router for Angular 2 and 1.x

9

DEMO

Page 18

LIFECYCLE-HOOKS

Page 19

Page 10: The new component router for Angular 2 and 1.x

10

What are Lifecycle-Hooks?

Methods within Components

Are called at specific times ("events")

Page 20

Life-Cycle-Hooks

OnActivate routerOnActivate

OnDeactivate routerOnDeactivate

CanDeactivate routerCanDeactivate

@CanActivate

Page 11: The new component router for Angular 2 and 1.x

11

CanActivate and CanDeactivate

Possible Results

true

false

Promise

Resolve with true or false

Page 22

DEMO

Page 23

Page 12: The new component router for Angular 2 and 1.x

12

AUX-ROUTES

Page 24

Aux-Routes

Page 25

Logo + Menu

Men

u 2

Footer

SPAPlaceholder

Named Placeholder

Page 13: The new component router for Angular 2 and 1.x

13

Aux-Routes

Page 26

Logo + Menu

Men

u 2

Footer

SPAFlight-

Component

Named Placeholder

/FlightApp/flights

Aux-Routes

Page 27

Logo + Menu

Men

u 2

Footer

SPAFlight-

Component

Info-Component

/FlightApp/flights(info)

Page 14: The new component router for Angular 2 and 1.x

14

Aux-Routes

Page 28

Logo + Menu

Men

u 2

Footer

SPAFlight-

Component

Info-Component

/FlightApp/flights(info/modal)/edit/17

Summary

Component Router: New Routing-Solution for Angular

2 and AngularJS 1.x

Lazy Loading

Hierarchical Routing

Lifecycle-Hooks

Aux Routes

Page 29

Page 15: The new component router for Angular 2 and 1.x

15

[email protected]

SOFTWAREarchitekt.at

ManfredSteyer

Contact