mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
test(alert): dismiss alert, then run nav.pop()
This commit is contained in:
@ -206,7 +206,7 @@ class ModalFirstPage {
|
||||
buttons: [
|
||||
{
|
||||
text: 'Destructive',
|
||||
style: 'destructive',
|
||||
role: 'destructive',
|
||||
handler: () => {
|
||||
console.log('Destructive clicked');
|
||||
}
|
||||
@ -217,9 +217,26 @@ class ModalFirstPage {
|
||||
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',
|
||||
style: 'cancel',
|
||||
role: 'cancel',
|
||||
handler: () => {
|
||||
console.log('cancel this clicked');
|
||||
}
|
||||
|
@ -643,13 +643,16 @@ export class NavController extends Ion {
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @param {number} startIndex The starting index to remove views from the nav stack
|
||||
* @param {removeCount} [opts={}] The number of views to remove, defaults to remove `1`.
|
||||
* @param {object} [opts={}] Any options you want to use pass to transtion
|
||||
* @returns {Promise} Returns a promise when the view has been removed
|
||||
* @param {number} [startIndex] The starting index to remove pages from the stack. Default is the index of the last page.
|
||||
* @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.
|
||||
* @returns {Promise} Returns a promise when the page has been removed.
|
||||
*/
|
||||
remove(startIndex: number, removeCount: number = 1, opts: any = {}): Promise<any> {
|
||||
if (startIndex < 0 || startIndex >= this._views.length) {
|
||||
remove(startIndex: number = -1, removeCount: number = 1, opts: any = {}): Promise<any> {
|
||||
if (startIndex === -1) {
|
||||
startIndex = this._views.length - 1;
|
||||
|
||||
} else if (startIndex < 0 || startIndex >= this._views.length) {
|
||||
return Promise.reject("remove index out of range");
|
||||
}
|
||||
|
||||
|
@ -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 {Config} from '../../config/config';
|
||||
|
@ -1,7 +1,7 @@
|
||||
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 {NavParams, NavController, ViewController, IONIC_DIRECTIVES} from 'ionic/ionic';
|
||||
import {NavParams, ViewController, IONIC_DIRECTIVES} from 'ionic/ionic';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -127,6 +127,7 @@ class FirstPage {
|
||||
<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 (click)="setPages()">setPages() (Go to PrimaryHeaderPage, FirstPage 1st in history)</button></p>
|
||||
<p><button (click)="presentAlert()">Present Alert</button></p>
|
||||
</ion-content>
|
||||
`
|
||||
})
|
||||
@ -157,6 +158,31 @@ class FullPage {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user