test(alert): dismiss alert, then run nav.pop()

This commit is contained in:
Adam Bradley
2016-01-29 23:31:51 -06:00
parent 6a96dae283
commit ecb5e4f031
4 changed files with 57 additions and 11 deletions

View File

@ -206,7 +206,7 @@ class ModalFirstPage {
buttons: [ buttons: [
{ {
text: 'Destructive', text: 'Destructive',
style: 'destructive', role: 'destructive',
handler: () => { handler: () => {
console.log('Destructive clicked'); console.log('Destructive clicked');
} }
@ -217,9 +217,26 @@ class ModalFirstPage {
console.log('Archive clicked'); console.log('Archive clicked');
} }
}, },
{
text: 'Go To Root',
handler: () => {
// overlays are added and removed from the root navigation
// find the root navigation, and pop this alert
// when the alert is done animating out, then pop off the modal
this.nav.rootNav.pop().then(() => {
this.nav.rootNav.pop();
});
// by default an alert will dismiss itself
// however, we don't want to use the default
// but rather fire off our own pop navigation
// return false so it doesn't pop automatically
return false;
}
},
{ {
text: 'Cancel', text: 'Cancel',
style: 'cancel', role: 'cancel',
handler: () => { handler: () => {
console.log('cancel this clicked'); console.log('cancel this clicked');
} }

View File

@ -643,13 +643,16 @@ export class NavController extends Ion {
* } * }
* ``` * ```
* *
* @param {number} startIndex The starting index to remove views from the nav stack * @param {number} [startIndex] The starting index to remove pages from the stack. Default is the index of the last page.
* @param {removeCount} [opts={}] The number of views to remove, defaults to remove `1`. * @param {number} [removeCount] The number of pages to remove, defaults to remove `1`.
* @param {object} [opts={}] Any options you want to use pass to transtion * @param {object} [opts={}] Any options you want to use pass to transtion.
* @returns {Promise} Returns a promise when the view has been removed * @returns {Promise} Returns a promise when the page has been removed.
*/ */
remove(startIndex: number, removeCount: number = 1, opts: any = {}): Promise<any> { remove(startIndex: number = -1, removeCount: number = 1, opts: any = {}): Promise<any> {
if (startIndex < 0 || startIndex >= this._views.length) { if (startIndex === -1) {
startIndex = this._views.length - 1;
} else if (startIndex < 0 || startIndex >= this._views.length) {
return Promise.reject("remove index out of range"); return Promise.reject("remove index out of range");
} }

View File

@ -1,4 +1,4 @@
import {Component, Directive, ElementRef, Host, Input, Optional, forwardRef, Inject, NgZone, Compiler, AppViewManager, Renderer, ViewContainerRef, Type} from 'angular2/core'; import {Component, ElementRef, Input, Optional, NgZone, Compiler, AppViewManager, Renderer, Type, ViewChild} from 'angular2/core';
import {IonicApp} from '../app/app'; import {IonicApp} from '../app/app';
import {Config} from '../../config/config'; import {Config} from '../../config/config';

View File

@ -1,7 +1,7 @@
import {Component, Type} from 'angular2/core'; import {Component, Type} from 'angular2/core';
import {App, NavController} from 'ionic/ionic'; import {App, NavController, Alert} from 'ionic/ionic';
import {Page, Config, IonicApp} from 'ionic/ionic'; import {Page, Config, IonicApp} from 'ionic/ionic';
import {NavParams, NavController, ViewController, IONIC_DIRECTIVES} from 'ionic/ionic'; import {NavParams, ViewController, IONIC_DIRECTIVES} from 'ionic/ionic';
@Component({ @Component({
@ -127,6 +127,7 @@ class FirstPage {
<p><button (click)="pushFirstPage()">Push to FirstPage</button></p> <p><button (click)="pushFirstPage()">Push to FirstPage</button></p>
<p><button class="e2eFrom2To1" nav-pop>Pop with NavPop (Go back to 1st)</button></p> <p><button class="e2eFrom2To1" nav-pop>Pop with NavPop (Go back to 1st)</button></p>
<p><button (click)="setPages()">setPages() (Go to PrimaryHeaderPage, FirstPage 1st in history)</button></p> <p><button (click)="setPages()">setPages() (Go to PrimaryHeaderPage, FirstPage 1st in history)</button></p>
<p><button (click)="presentAlert()">Present Alert</button></p>
</ion-content> </ion-content>
` `
}) })
@ -157,6 +158,31 @@ class FullPage {
this.nav.push(FirstPage); this.nav.push(FirstPage);
} }
presentAlert() {
let alert = Alert.create();
alert.setTitle('Hello Alert');
alert.setMessage('Dismiss this alert, then pop one page');
alert.addButton({
text: 'Dismiss',
role: 'cancel',
handler: () => {
// overlays are added and removed from the root navigation
// ensure you using the root navigation, and pop this alert
// when the alert is done animating out, then pop off the active page
this.nav.rootNav.pop().then(() => {
this.nav.rootNav.pop();
});
// by default an alert will dismiss itself
// however, we don't want to use the default
// but rather fire off our own pop navigation
// return false so it doesn't pop automatically
return false;
}
});
this.nav.present(alert);
}
} }