angular - 如何在 Ionic 5 Angular 应用程序中将 cssClass 分配给 ActionSheetController 内的按钮?
问题描述
我正在尝试将 CSS 类添加到 Ionic 5 Angular 应用程序中 ActionSheetController 内的按钮,但未分配该类。
我在网上查找了一些建议将 CSS 代码放入的解决方案app.component.scss
,我已经尝试过,但它仍然无法正常工作。
我在mechanic.page.ts
下面创建控制器:
this.actionSheetCtrl.create({
header: 'Choose an Action',
cssClass: 'myPage',
buttons: [
{
text: 'Book Appointment',
cssClass: 'myActionSheetBtnStyle',
icon: 'calendar-outline',
handler: () => {
this.goToProfile(mechanicId);
}
}
]
}).then(actionSheetEl => {
actionSheetEl.present();
});
这是CSS中的app.component.scss
:
.myPage {
.myActionSheetBtnStyle {
color: red;
}
}
当我打开控制器时,按钮不是红色的。有人可以告诉我我需要做哪些改变才能让它工作吗?
解决方案
不要将其添加到app.component.scss
. 它应该global.scss
在 app 文件夹中。使用 css 变量来设置离子组件的样式也是一种很好的做法。在这种情况下,它应该是这样的:
.myPage {
.myActionSheetBtnStyle {
--button-color: red;
}
}
推荐阅读
- angular - 如何获取 ngx-Summernote 运行时的价值
- c# - 我试图运行一个网站,但没有任何效果
- flutter - Flutter 按钮,右边是图片,中间是文字
- java - 如何编码“?” 在 springboot RestTemplate 交换方法的 url 中?
- pandas - AWS lambda 任务在处理来自 S3 存储桶的数据时出现大数据超时问题
- android - 在 Android 中获取应用程序启动时的所有远程通知
- android - java.lang.IllegalStateException: findViewById(R.id.addNotes) 不能为空
- tensorflow - 使用 train_on_batch 为每个 epoch 获得相同的准确性和损失
- javascript - 如何在chartjs和角度中的自定义工具提示和普通工具提示之间切换
- excel - 创建数据透视表时未找到数据源名称且未指定默认驱动程序