ionic-framework - ionic V4 : ion-modal just like ion-alert

标签 ionic-framework ionic4

如果将输入替换为文本区域,则以下 ion-alert 正是我们所需要的;但是,ion-alert 不支持 ion-textarea

如何使用 ion-modal 实现完全相同的外观和感觉?

我们使用的是 Ionic,没有 Angular(Ionic 核心)。

ionic 警报代码

 const alert = await alertController.create({
   header: 'Would you be willing to leave feedback?',
   inputs: [
   {
     placeholder: 'enter text'
   }],
   buttons: [
     {
       text: 'Cancel',
       role: 'cancel',
       cssClass: 'secondary',
       handler: _ => {
         alert.dismiss();
         console.log('cancel');
       }
     }, {
       text: 'Submit',
       handler: _ => {
         alert.dismiss();
         console.log('submit');
       }
     }
   ]
 });
 alert.present();

ion-alert

尝试的 ionic 模式代码

const modalController = $('ion-modal-controller')[0];
await modalController.componentOnReady();

const modalElement = await modalController.create({
  showBackdrop: true,
  component:
    $(`<div>
          <h2>Would you be willing to provide feedback?</h2>

          <div>
            <ion-button>Cancel</ion-button>
            <ion-button>Submit</ion-button>
          </div>
      </div>`)[0]
});
await modalElement.present();

ion-modal

最佳答案

在调用模态的页面中:

async book() {
   const modal = await this.modalController.create({
	component: BookModal,
	componentProps: { value: 123 },
	showBackdrop: true,
	backdropDismiss: true,
	cssClass: ['booking-modal']
   });
   return await modal.present();
}

关键点是cssClass。然后在 theme/variable.scss 中,在文件末尾添加类,如下所示:

.booking-modal {
	--height: 50% !important;
}

** 注意:这可能不是正确的方法,但在现阶段它对我有用。寻找更好的解决方案。

关于ionic-framework - ionic V4 : ion-modal just like ion-alert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53057199/

相关文章:

ionic-framework - ionic 4 ionic 按钮不起作用

css - 页面中的 Ionic 4 SCSS 被忽略

ios - 无法使用 Azure DevOps 构建使用 Cordova/Ionic 构建的 iOS 应用程序

javascript - 在 Ionic Framework with Crosswalk 中 $state.go() 之后,之前的数据仍然存在

android - 为什么 HTML5 地理定位比 Android 上的本地定位慢?

javascript - 带有左右箭头的文本框-Ionic4

ios - Ionic Framework for ios - 开发模式

angular - 如何通过循环动态调用函数?

javascript - 根据用户是否登录更改网站上的文本

css - 防止 ionic 徽章折叠和隐藏信息