fix(angular): back-button

This commit is contained in:
Manu Mtz.-Almeida
2018-04-03 13:34:24 +02:00
parent 685d5a166c
commit 1f78390c84
2 changed files with 7 additions and 34 deletions

View File

@ -1,12 +1,16 @@
import { Directive, HostListener, Optional } from '@angular/core';
import { Directive, HostListener, Input, Optional } from '@angular/core';
import { IonRouterOutlet } from './ion-router-outlet';
import { Router } from '@angular/router';
@Directive({
selector: 'ion-back-button'
})
export class IonBackButton {
@Input() defaultHref: string;
constructor(
@Optional() private router: Router,
@Optional() private routerOutlet: IonRouterOutlet,
) {}
@ -14,6 +18,8 @@ export class IonBackButton {
onClick() {
if (this.routerOutlet && this.routerOutlet.canGoBack()) {
this.routerOutlet.pop();
} else if (this.router && this.defaultHref != null) {
this.router.navigateByUrl(this.defaultHref);
}
}
}

View File

@ -1,33 +0,0 @@
import { ComponentRef } from '@angular/core';
export function runTransition(enteringRef: ComponentRef<any>, leavingRef: ComponentRef<any>): Promise<void> {
const enteringElm = (enteringRef && enteringRef.location && enteringRef.location.nativeElement);
const leavingElm = (leavingRef && leavingRef.location && leavingRef.location.nativeElement);
if (!enteringElm && !leavingElm) {
return Promise.resolve();
}
return tr(enteringElm, leavingElm);
}
function tr(enteringElm: HTMLElement, leavingElm: HTMLElement): Promise<void> {
console.log('transition start');
return new Promise(resolve => {
setTimeout(() => {
if (enteringElm) {
enteringElm.classList.add('show-page');
}
if (leavingElm) {
leavingElm.classList.remove('show-page');
}
resolve();
}, 750);
});
}