Hello people! I have a problem with the component ion-modal and I don’t know how to fix it.
I have a contrelled modal in my Angular (16) + Ionic (7) application:
<div *ngFor="let timeframe of match.timeframes; index as i" class="ion-padding-top">
<ion-button expand="block" (click)="openModal(i)">
From: {{ convertDate(timeframe.start) | date : "short" }} to: {{ convertDate(timeframe.end) | date : "short" }}
</ion-button>
</div>
The openModal
function is the following:
async openModal(index: number) {
if (!this.match?.timeframes) return;
this.selectedTime = this.match.timeframes[index]?.start;
const modal = await this.modalCtrl.create({
component: AcceptModal,
componentProps: {
timeframe: this.match.timeframes[index],
},
});
modal.present();
const { data, role } = await modal.onWillDismiss();
if (role === "confirm") {
this.accept(data);
}
}
And the AcceptModal
component is the following:
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button color="medium" (click)="cancel()">Cancel</ion-button>
</ion-buttons>
<ion-buttons slot="end">
<ion-button color="medium" (click)="confirm()">Confirm</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content class="block">
<ion-item>
<ion-datetime confirm="" [(ngModel)]="selectedTimeframe" min={{timeframe?.start}}
max={{timeframe?.end}}></ion-datetime>
</ion-item>
</ion-content>
This is the ts:
import { Component, Input } from "@angular/core";
import { IonicModule, ModalController } from "@ionic/angular";
import { Timeframe } from "../api/v1";
import { FormsModule } from "@angular/forms";
@Component({
selector: "accept-modal",
templateUrl: "./accept-modal.component.html",
styleUrls: ["./accept-modal.component.scss"],
standalone: true,
imports: [IonicModule, FormsModule],
})
export class AcceptModal {
@Input() timeframe: Timeframe | null = null;
selectedTimeframe: string | undefined = "";
constructor(private modalCtrl: ModalController) {}
ngOnInit() {
this.selectedTimeframe = this.timeframe?.start;
}
cancel() {
return this.modalCtrl.dismiss(null, "cancel");
}
confirm() {
return this.modalCtrl.dismiss(this.selectedTimeframe, "confirm");
}
}
On the browser the modal works perfectly, but on the android emulator and on a real device the modal won’t even show. No errors whatsoever…
So I tried the inline modal, which is the one reccomended in the documentation:
<ion-button id="open-modal" expand="block">Open</ion-button>
<ion-modal trigger="open-modal">
<ng-template>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
</ion-buttons>
<ion-title>Welcome</ion-title>
<ion-buttons slot="end">
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-item>
<ion-input label="Enter your name" labelPlacement="stacked" type="text" placeholder="Your name"></ion-input>
</ion-item>
</ion-content>
</ng-template>
</ion-modal>
and even this one won’t open…
How can I fix this?