From 68f3c6c0c841e61dab7daf7cc86ebdaf05276ca4 Mon Sep 17 00:00:00 2001 From: Dan Bucholtz Date: Thu, 2 Mar 2017 14:55:10 -0600 Subject: [PATCH] refactor(nav): restructure nav component to separate modules, support async component loading restructure nav component to separate modules, support async component loading --- src/components/nav/nav-pop-anchor.ts | 39 +++++++++++++++++++++++++++ src/components/nav/nav-pop.ts | 39 +-------------------------- src/components/nav/nav-push-anchor.ts | 36 +++++++++++++++++++++++++ src/components/nav/nav-push.ts | 36 +------------------------ src/components/nav/nav.ts | 4 ++- 5 files changed, 80 insertions(+), 74 deletions(-) create mode 100644 src/components/nav/nav-pop-anchor.ts create mode 100644 src/components/nav/nav-push-anchor.ts diff --git a/src/components/nav/nav-pop-anchor.ts b/src/components/nav/nav-pop-anchor.ts new file mode 100644 index 0000000000..e3ff6582f1 --- /dev/null +++ b/src/components/nav/nav-pop-anchor.ts @@ -0,0 +1,39 @@ +import { AfterContentInit, Directive, Optional } from '@angular/core'; + +import { DeepLinker } from '../../navigation/deep-linker'; +import { ViewController } from '../../navigation/view-controller'; + +import { NavPop } from './nav-pop'; + +/** + * @private + */ +@Directive({ + selector: 'a[navPop]', + host: { + '[attr.href]': '_href' + } +}) +export class NavPopAnchor implements AfterContentInit { + + _href: string; + + constructor( + @Optional() public host: NavPop, + public linker: DeepLinker, + @Optional() public viewCtrl: ViewController) {} + + updateHref() { + if (this.host && this.viewCtrl) { + const previousView = this.host._nav.getPrevious(this.viewCtrl); + this._href = (previousView && this.linker.createUrl(this.host._nav, this.viewCtrl.component, this.viewCtrl.data)) || '#'; + + } else { + this._href = '#'; + } + } + + ngAfterContentInit() { + this.updateHref(); + } +} diff --git a/src/components/nav/nav-pop.ts b/src/components/nav/nav-pop.ts index 3aa5ef7e22..05301c8e93 100644 --- a/src/components/nav/nav-pop.ts +++ b/src/components/nav/nav-pop.ts @@ -1,8 +1,6 @@ -import { AfterContentInit, Directive, HostListener, Optional } from '@angular/core'; +import { Directive, HostListener, Optional } from '@angular/core'; -import { DeepLinker } from '../../navigation/deep-linker'; import { NavController } from '../../navigation/nav-controller'; -import { ViewController } from '../../navigation/view-controller'; /** @@ -53,38 +51,3 @@ export class NavPop { } } - - -/** - * @private - */ -@Directive({ - selector: 'a[navPop]', - host: { - '[attr.href]': '_href' - } -}) -export class NavPopAnchor implements AfterContentInit { - - _href: string; - - constructor( - @Optional() public host: NavPop, - public linker: DeepLinker, - @Optional() public viewCtrl: ViewController) {} - - updateHref() { - if (this.host && this.viewCtrl) { - const previousView = this.host._nav.getPrevious(this.viewCtrl); - this._href = (previousView && this.linker.createUrl(this.host._nav, this.viewCtrl.component, this.viewCtrl.data)) || '#'; - - } else { - this._href = '#'; - } - } - - ngAfterContentInit() { - this.updateHref(); - } - -} diff --git a/src/components/nav/nav-push-anchor.ts b/src/components/nav/nav-push-anchor.ts new file mode 100644 index 0000000000..7df78c2cd3 --- /dev/null +++ b/src/components/nav/nav-push-anchor.ts @@ -0,0 +1,36 @@ +import { AfterContentInit, Directive, Host, Optional } from '@angular/core'; + +import { DeepLinker } from '../../navigation/deep-linker'; + +import { NavPush } from './nav-push'; + +/** + * @private + */ +@Directive({ + selector: 'a[navPush]', + host: { + '[attr.href]': '_href' + } +}) +export class NavPushAnchor implements AfterContentInit { + + _href: string; + + constructor( + @Host() public host: NavPush, + @Optional() public linker: DeepLinker) {} + + updateHref() { + if (this.host && this.linker) { + this._href = this.linker.createUrl(this.host._nav, this.host.navPush, this.host.navParams) || '#'; + + } else { + this._href = '#'; + } + } + + ngAfterContentInit() { + this.updateHref(); + } +} diff --git a/src/components/nav/nav-push.ts b/src/components/nav/nav-push.ts index 5dd2579371..cd8f02e78b 100644 --- a/src/components/nav/nav-push.ts +++ b/src/components/nav/nav-push.ts @@ -1,6 +1,5 @@ -import { AfterContentInit, Directive, Host, HostListener, Input, Optional } from '@angular/core'; +import { Directive, HostListener, Input, Optional } from '@angular/core'; -import { DeepLinker } from '../../navigation/deep-linker'; import { NavController } from '../../navigation/nav-controller'; /** @@ -79,37 +78,4 @@ export class NavPush { } return true; } - -} - -/** - * @private - */ -@Directive({ - selector: 'a[navPush]', - host: { - '[attr.href]': '_href' - } -}) -export class NavPushAnchor implements AfterContentInit { - - _href: string; - - constructor( - @Host() public host: NavPush, - @Optional() public linker: DeepLinker) {} - - updateHref() { - if (this.host && this.linker) { - this._href = this.linker.createUrl(this.host._nav, this.host.navPush, this.host.navParams) || '#'; - - } else { - this._href = '#'; - } - } - - ngAfterContentInit() { - this.updateHref(); - } - } diff --git a/src/components/nav/nav.ts b/src/components/nav/nav.ts index 6ccc896b5e..a27bce7999 100644 --- a/src/components/nav/nav.ts +++ b/src/components/nav/nav.ts @@ -111,7 +111,9 @@ export class Nav extends NavControllerBase implements AfterViewInit { let navSegment = this._linker.initNav(this); if (navSegment && navSegment.component) { // there is a segment match in the linker - this.setPages(this._linker.initViews(navSegment), null, null); + this._linker.initViews(navSegment).then(views => { + this.setPages(views, null, null); + }); } else if (this._root) { // no segment match, so use the root property