IONIC4 使用自定义弹出框 -ModalController

1. 使用

1.在使用的界面引入
import { ModalController } from '@ionic/angular';
2.在使用的界面的 .module.ts 引入要弹出的界面,并添加到 declarations 数组中, 在 @NgModule中
增加 entryComponents 属性,把要弹出的界面添加到 entryComponents

例如:

 

import { PicturepreviewPage } from '../viewmodels/picturepreview.page';
 const routes: Routes = [
   {
    path: '',
    component: WorkorderPage
   }
];

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    SignaturePadModule,
    RouterModule.forChild(routes)
  ],
  declarations: [WorkorderPage,PicturepreviewPage],
  entryComponents: [PicturepreviewPage]
})
export class WorkorderPageModule {}

我引入一个 PicturepreviewPage page 在 declarations 中和 entryComponents 中声明该page

  1. 在需要弹出模态框的界面同样引入该 page
    调用 ModalControllercreate方法
    其中介绍三个重要参数:
    1:component 为要弹出的组件,值为你引入的这个page
    2:componentProps为要传递过去的参数,值任意
    3: cssClass 为样式,例如设置透明度等

例子:

 

async showConditions() {
 let modal = await this.modalController.create({
   component: ConditionsPage,
   mode: "md",
   componentProps: {
     "imgs": this.imgs,
     "flag": false
   },
   cssClass: "conditions"
 });
 modal.present();

 //模态框被关闭后回回调该方法 res 为返回值
 modal.onDidDismiss().then(res => {
   console.log(res);
 })

}
  1. 关闭模态框
    例如点击确认后,获取模态框传回的值

 

    this.modalController.getTop().then(event => {
      event.dismiss({
        test:"11"
      },"test");
    })

//源码查看
    'dismiss': (data?: any, role?: string | undefined) => Promise<boolean>;

data 为传递回去的参数,role为 角色
官网地址:https://ionicframework.com/docs/api/modal

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值