refactor(nav): restructure nav component to separate modules, support async component loading

restructure nav component to separate modules, support async component loading
This commit is contained in:
Dan Bucholtz
2017-03-02 14:55:10 -06:00
parent d896682799
commit 68f3c6c0c8
5 changed files with 80 additions and 74 deletions

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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