2017-06-22 50 views
4

我建立一個離子2應用程序,我現在用的是以下組件如何點擊它外面當離子2

http://ionicframework.com/docs/components/#alert

import { AlertController } from 'ionic-angular'; 

export class MyPage { 
    constructor(public alertCtrl: AlertController) { 
    } 

    showAlert() { 
    let alert = this.alertCtrl.create({ 
     title: 'New Friend!', 
     subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!', 
     buttons: ['OK'] 
    }); 
    alert.present(); 
    } 
} 

不關閉該警告框我怎樣才能確保當我在盒子外面點擊時,警報不會被解除?

回答

11

假正如你可以看到the AlertController docs,你可以在創建警報時使用(布爾)選項:

無論警報應通過點擊背景而被解僱。默認 真正

import { AlertController } from 'ionic-angular'; 

export class MyPage { 

    constructor(public alertCtrl: AlertController) {} 

    showAlert() { 
    let alert = this.alertCtrl.create({ 
     title: 'New Friend!', 
     subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!', 
     buttons: ['OK'], 
     enableBackdropDismiss: false // <- Here! :) 
    }); 

    alert.present(); 
    } 
} 
0

集enableBackdropDismiss:在alertCtrl.create選項

0

嘗試像這樣,把這個代碼爲您處理handler:() => { console.log(this.viewCtrl.dismiss()); }