Kat*_*lle 3 alert popup ionic3
我有一个可以删除另一个用户的应用程序。当用户单击删除按钮时,将出现一个弹出窗口,询问用户是否确定要执行此操作。当用户单击确认时,我希望删除该用户。我最初是通过在按钮上放置remove方法来实现此目的的,如下所示:
<button ion-button (click)="remove(i);">Delete</button>
Run Code Online (Sandbox Code Playgroud)
在我的.ts中,我有以下代码:
this.items = [
{user: 'UserA'},
{user: 'UserB'}
];
remove(no) {
(this.items).splice(no, 1);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,现在,当用户单击按钮时,顶部打开弹出窗口的方法称为:
<button ion-button (click)="showConfirmAlert();">Delete</button>
Run Code Online (Sandbox Code Playgroud)
而且我现在不确定如何从列表中删除该项目。
showConfirmAlert() {
let alert = this.alertCtrl.create({
title: 'Confirm delete user',
message: 'Are you sure you want to permanently delete this user?',
buttons: [
{
text: 'No',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Yes',
handler: () => {
}
}
]
})
}
Run Code Online (Sandbox Code Playgroud)
我是否需要在showConfirmAlert方法内编写一个单独的remove函数?我该怎么做呢?抱歉,这里很新,任何帮助将不胜感激!
在您的html文件中:
<button ion-button (click)="showConfirmAlert(i);">Delete</button>
Run Code Online (Sandbox Code Playgroud)
在您的ts文件中:
showConfirmAlert(i) {
let alert = this.alertCtrl.create({
title: 'Confirm delete user',
message: 'Are you sure you want to permanently delete this user?',
buttons: [
{
text: 'No',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Yes',
handler: () => {
this.items.splice(i,1);
}
}
]
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3987 次 |
| 最近记录: |