angular - Angular 风格
问题描述
我对 ngStyle 有疑问,我根据悬停变量放置样式。它有效,但我一直看到警告
Type {color: string, background: string, 'border-color': string} | string is not assignable to type {[p: string]: string}
我的功能
getSuccessBtnStyleHover() {
if (this.data && this.data.btnSBorderHColor && this.data.btnSBackgroundHColor && this.data.btnSTextHColor) {
return {
'color': this.data.btnSTextHColor,
'background': this.data.btnSBackgroundHColor,
'border-color': this.data.btnSBorderHColor,
};
}
return '';
}
我试过了
[ngStyle]="(hovered && themeService.getSuccessBtnStyleHover()) || (!hovered && themeService.getSuccessBtnStyle())"
(mouseover)="hovered = true"
(mouseout)="hovered = false"
和
[ngStyle]="hovered ? themeService.getSuccessBtnStyleHover() : themeService.getSuccessBtnStyle()"
(mouseover)="hovered = true"
(mouseout)="hovered = false"
哪里有问题?
谢谢你的帮助
解决方案
您将返回一个空字符串作为默认条件。所以返回类型要么是你的 CSS 对象,要么是一个空字符串。尝试返回{}
而不是''
推荐阅读
- vbscript - 无法从 vbscript 更新测试集中的测试人员名称
- android - com.google.android.gms.ads 的 NullPointerException
- google-cloud-platform - 我想识别Terraform的执行环境的公网IP并添加到防火墙规则中
- machine-learning - 一种更不平衡的compute_class_weight方法
- c# - 如何访问在 Azure AKS 上配置的 RabbitMQ 集群以在队列上发送消息?
- stata - 使用 for 循环删除递归回归中的实体
- c# - 如何定位(世界空间)画布文本以在 Unity 中创建尺寸叠加
- angular - 在角度服务中初始化时,array.some 在运行 ng-test 期间不是函数
- python - Kivy 和 PyUpdater 日志之间的冲突
- opencv - OpenCV 平均划分边缘并占据主导地位