The data can be read in through the onWillDismiss or onDidDismiss linked to the modal after it has been dismissed:
const { data } = await modal.onWillDismiss();
console.log(data);
Lazy Loading
When lazy loading a modal, remember that the modal will be loaded when the module (that imports the modal's module) is loaded, not when the modal is opened.
Consider the case of a CalendarComponent and an EventModal.
By clicking a button in the CalendarComponent, the modal appears.
Because the modal is produced in the CalendarComponentModule, the EventModalModule must be included in the CalendarComponentModule in Angular:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { CalendarComponent } from './calendar.component';
import { EventModalModule } from '../modals/event/event.module';
@NgModule({
declarations: [
CalendarComponent
],
imports: [
IonicModule,
CommonModule,
EventModalModule
],
exports: [
CalendarComponent
]
})
export class CalendarComponentModule {}
Modals in iOS mode can be presented in a card-like format and swiped to close.
The card-style display and the swipe to close action aren't mutually exclusive, so you can employ whichever features you like.
On iPhone-sized devices, card-style models do not have a background. As a result, the --background-opacity parameter has no impact.
If you are building an application that makes use of ion-tabs, it is suggested to bring up ion-router-outlet using this.routerOutlet.parentOutlet.nativeEl, or else when the modal opens, the tab bar will not scale down.
When the modal was dismissed, this method returns a promise that resolves.
Signature:
onDidDismiss() => Promise>
3) onWillDismiss():
Returns a promise indicating when the modal will be dismissed.
Signature:
onWillDismiss() => Promise>
4) Present():
After the modal overlay has been generated, present it.
Signature:
present() => Promise
CSS Custom Properties:
Name
Description
---backdrop-opacity
The opacity of the backdrop
--background
Background of the model content
--border-color
Border color of the model content
--border-radius
Border radius of the model content
--border-style
Border style of the model content
--border-width
The border width of the model content
--height
Height of the model
--max-height
Maximum height of the model
--min-height
Minimum height of the model
--max-width
Maximum width of the model
--min-width
Minimum width of the model
--width
Width of model
Conclusion
In this blog, we have seen what is ion-model in the Ionic framework and how to use ion-model in your project. As we see above We can use ion-model as a select component when there are many options to choose from or to filter items in a list.
The data can be read in through the onWillDismiss or onDidDismiss linked to the modal after it has been dismissed:
const { data } = await modal.onWillDismiss();
console.log(data);
Lazy Loading
When lazy loading a modal, remember that the modal will be loaded when the module (that imports the modal's module) is loaded, not when the modal is opened.
Consider the case of a CalendarComponent and an EventModal.
By clicking a button in the CalendarComponent, the modal appears.
Because the modal is produced in the CalendarComponentModule, the EventModalModule must be included in the CalendarComponentModule in Angular:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { CalendarComponent } from './calendar.component';
import { EventModalModule } from '../modals/event/event.module';
@NgModule({
declarations: [
CalendarComponent
],
imports: [
IonicModule,
CommonModule,
EventModalModule
],
exports: [
CalendarComponent
]
})
export class CalendarComponentModule {}
Modals in iOS mode can be presented in a card-like format and swiped to close.
The card-style display and the swipe to close action aren't mutually exclusive, so you can employ whichever features you like.
On iPhone-sized devices, card-style models do not have a background. As a result, the --background-opacity parameter has no impact.
If you are building an application that makes use of ion-tabs, it is suggested to bring up ion-router-outlet using this.routerOutlet.parentOutlet.nativeEl, or else when the modal opens, the tab bar will not scale down.
When the modal was dismissed, this method returns a promise that resolves.
Signature:
onDidDismiss() => Promise>
3) onWillDismiss():
Returns a promise indicating when the modal will be dismissed.
Signature:
onWillDismiss() => Promise>
4) Present():
After the modal overlay has been generated, present it.
Signature:
present() => Promise
CSS Custom Properties:
Name
Description
---backdrop-opacity
The opacity of the backdrop
--background
Background of the model content
--border-color
Border color of the model content
--border-radius
Border radius of the model content
--border-style
Border style of the model content
--border-width
The border width of the model content
--height
Height of the model
--max-height
Maximum height of the model
--min-height
Minimum height of the model
--max-width
Maximum width of the model
--min-width
Minimum width of the model
--width
Width of model
Conclusion
In this blog, we have seen what is ion-model in the Ionic framework and how to use ion-model in your project. As we see above We can use ion-model as a select component when there are many options to choose from or to filter items in a list.
Author Bio
Author Name: Hemanshu Kalsariya
Hemanshu Kalsariya is an adept and creative Angular Developer. With great exposure to design patterns and frontend development, he frequently shares incredible Angular insights on various platforms.