【问题标题】:How to open a modal in ionic 5?如何在 ionic 5 中打开模式?
【发布时间】:2020-05-12 07:29:47
【问题描述】:
我想在 ionic 5 中打开一个模态。但不知何故,我找不到可以导出我想使用的模态/组件的 component.module.ts 文件。他们是否更改了该系统,如何使用 ionic 5 完成?你知道一个文档吗?整个系统似乎发生了变化,就像总是有一个page-routing.module.ts。在每个页面文件中。
【问题讨论】:
标签:
ionic-framework
ionic3
ionic4
【解决方案1】:
打开模态没有什么新变化。
在entryComponents and declarations 中将 modalPage 或 modalComponent 添加到 app.module.ts [或 Home.module.ts 如果延迟加载]
app.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { FolderPageRoutingModule } from './folder-routing.module';
import { FolderPage } from './folder.page'; //from where you open
import { ModalPage } from '../modal/modal.page';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
FolderPageRoutingModule
],
declarations: [ModalPage],
entryComponents: [ModalPage] //modal page
})
export class FolderPageModule {}
然后从相应的页面打开你的模态。
async presentModal() {
const modal = await this.modalController.create({
component: ModelComponent,
componentProps: { value: 123 }
});
await modal.present();
}
希望对您有所帮助。