2017-07-20 19 views
0

我有一個警報控制器,當觸發時,打開,然後立即關閉,沒有我做任何事情。在Ionic 2停止alertCtrl自動觸發取消

let alert = this.alertCtrl.create({ 
    title: 'Requires Login', 
    message: 'Please register or log in to add to cart.', 
    buttons: [ 
     { 
     text: 'Cancel', 
     handler:() => { 
      console.log('Cancel clicked'); 
     } 
     }, 
     { 
     text: 'Login', 
     handler:() => { 
      this.logOut(); 
     } 
     } 
    ] 
    }); 
    alert.present(); 

我找不到任何錯事,我不知道是什麼原因造成這個問題?當我通過手機運行應用程序時,出現錯誤,但是當我通過瀏覽器運行它時,沒有錯誤。

+0

只在手機上發生的呢? –

+0

@SwapnilPatwa是隻在手機上 – maudulus

+0

嘗試添加'role:'cancel''取消按鈕。它應該是'文本:'取消',角色:'取消',處理程序:.........' –

回答

0

下面是從我目前的項目工作的例子

logout() { 
let confirm = this.alertCtrl.create({ 
    title: 'Confirm', 
    message: 'Are you sure you want to logout?', 
    buttons: [ 
    { 
     text: 'No', 
     handler:() => { } 
    }, 
    { 
     text: 'Yes', 
     handler:() => { 
     this.removeNotificationRegistrationAndLogOut(LoginPage, true); 
     } 
    } 
    ] 
}); 
confirm.present(); 
}