feat(routerDirection): refactors goBack

This commit is contained in:
Manu Mtz.-Almeida
2018-04-11 22:40:50 +02:00
parent d623b3b71f
commit 54d7a12bea
11 changed files with 95 additions and 47 deletions

View File

@ -5,7 +5,7 @@ export { RadioValueAccessor } from './control-value-accessors/radio-value-access
export { SelectValueAccessor } from './control-value-accessors/select-value-accessor';
export { TextValueAccessor } from './control-value-accessors/text-value-accessor';
export { GoBack } from './navigation/go-back';
export { RouterDirection } from './navigation/router-direction';
export { IonBackButton } from './navigation/ion-back-button';
export { NavDelegate } from './navigation/nav-delegate';
export { TabDelegate } from './navigation/tab-delegate';

View File

@ -1,17 +0,0 @@
import { Directive, HostListener } from '@angular/core';
import { NavController, NavIntent } from '../../providers/nav-controller';
@Directive({
selector: '[goBack]',
})
export class GoBack {
constructor(
private navCtrl: NavController,
) {}
@HostListener('click')
onClick() {
this.navCtrl.setIntent(NavIntent.Back);
}
}

View File

@ -0,0 +1,28 @@
import { Directive, HostListener, Input } from '@angular/core';
import { NavController, NavIntent } from '../../providers/nav-controller';
@Directive({
selector: '[routerDirection]',
})
export class RouterDirection {
@Input() routerDirection: string;
constructor(
private navCtrl: NavController,
) {}
@HostListener('click')
onClick() {
this.navCtrl.setIntent(textToIntent(this.routerDirection));
}
}
function textToIntent(direction: string) {
switch (direction) {
case 'forward': return NavIntent.Forward;
case 'back': return NavIntent.Back;
case 'root': return NavIntent.Root;
default: return NavIntent.Auto;
}
}

File diff suppressed because one or more lines are too long

View File

@ -94,9 +94,9 @@ const DECLARATIONS = [
c.TextValueAccessor,
// navigation
c.GoBack,
c.IonBackButton,
c.IonRouterOutlet,
c.RouterDirection,
c.NavDelegate,
c.TabDelegate,
c.TabsDelegate,