问题
I have been trying to achieve something like the above in ionic 4 but it seems like there is no hope for me cos it seems I can only use inputs and not a custom HTML & icons been passed on the alert. any idea on how to achieve this pls
async presentColor() {
const alert = await this.alertController.create({
header: "Choose Color",
inputs: [
{
name: "Red",
type: "checkbox",
label: "Red",
value: "Red",
checked: true
},
{
name: "Black",
type: "checkbox",
label: "Black",
value: "Black"
},
{
name: "purple",
type: "checkbox",
label: "Purple",
value: "Purple"
}
],
buttons: [
{
text: "Cancel",
role: "cancel",
cssClass: "secondary",
handler: (data) => {
console.log("Confirm Cancel", data);
}
},
{
text: "Ok",
handler: () => {
console.log("Confirm Ok");
}
}
]
});
回答1:
The Ionic team has not made alert components easily customizable so icons can be added to the alert component. See issue:
https://github.com/ionic-team/ionic/issues/7874
But you could easily create a modal component and reduce its size to be closer to that of the alert dialog box.
回答2:
Why you want use ion alert. You can use other components like popovers to do that
回答3:
I know this is a bit late, but I just created an npm package to handle adding an angular component into a popup.
来源:https://stackoverflow.com/questions/55132453/passing-html-template-and-icons-on-alert-ionic-4