在Ionic framework(v5)中,Alert上的按钮的role
属性的可能值是什么?
文档仅提及cancel
:https://ionicframework.com/docs/api/alert#buttons
您可以选择将role
属性加入至按钮,例如cancel
。
示例:
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: 'Okay',
handler: () => {
console.log('Confirm Okay');
}
}
]
2条答案
按热度按时间uoifb46i1#
I think role only have 1 property i.e
'cancel'
.As mentioned in Documentation:
"Optionally, a role property can be added to a button, such as cancel. If a cancel role is on one of the buttons, then if the alert is dismissed by tapping the backdrop, then it will fire the handler from the button with a cancel role."
So you can handle it when user dismiss it by clicking on backdrop. it means if you want to do something on cancellation but user dismiss alert by click outside(backdrop) you can still handle it.
7tofc5zh2#
Looking into the
alert-interface.ts
, the predefined roles are 'cancel' and 'destructive', but also it accepts any string you may want to use as roles.