gpt4 book ai didi

styles - ngStyle 内的函数调用被清理

转载 作者:行者123 更新时间:2023-12-03 23:04:18 25 4
gpt4 key购买 nike

我在使用 Angular 8 进行样式清理时遇到问题。
我多次使用 ngStyle,但这次我无法设置 td 的边框元素。
我正在尝试根据字段设置边框样式。如果这个领域有与我相关的内容,那么我会突出显示它,否则我不会。我不知道该字段的可能值的数量,也不知道确切的值:它是完全动态的,我只知道我感兴趣的值。
我正在从 .ts 中的函数返回边框样式文件。以下是代码片段:

<ng-container matColumnDef="{{cam}}">
<th mat-header-cell *matHeaderCellDef class="header"> {{cam}} </th>
<td mat-cell *matCellDef="let piano" class="cellaMagazzino" [ngStyle]=" {'border':shouldHighlight(piano[cam])}">
<div>
<!--content-->
</div>
</td>
</ng-container>
我的 typescript 功能如下所示:
shouldHighlight(element){
if (this.listaCommittenti == undefined && this.listaNumOrdine == undefined) {
let found = this.releventContentList.find(item => item.property == element.property)
let result = found != undefined ? '3px solid ' + this.myVariable["color"] : ""
return result
}
我其他时候使用过 ngStyle 调用函数,但在这种情况下,我收到错误消息:
警告:清理不安全的样式值 3px solid rgb(241, 196, 15)(见 http://g.co/ng/security#xss)。
是否有某种配置要做?有解决方法吗?

最佳答案

这对你有用吗?
typescript :

getHighlightColor():string {
return "rgba(255,255,255,1)";
}
shouldHighlight(): boolean {
return true;
}
HTML:
<td mat-cell [style.border-color]="getHighlightColor(piano[cam])" [ngClass]="{ 'highlighted': shouldHighlight(piano[cam])}"
CSS:
.highlighted{
border-width:3px;
border-style:solid;
border-color:transparent;
}

关于styles - ngStyle 内的函数调用被清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63616000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com