ngStyle 内的函数调用得到清理

Fed*_*oli 5 styles sanitize ng-style angular8

我在使用 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>
Run Code Online (Sandbox Code Playgroud)

我的打字稿函数如下所示:

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
}
Run Code Online (Sandbox Code Playgroud)

我其他时候使用 ngStyle 调用函数,但在这种情况下我收到错误:

警告:清理不安全样式值 ​​3px 实心 rgb(241, 196, 15)(请参阅http://g.co/ng/security#xss)。

是否需要进行某种配置?有解决方法吗?

Eli*_*lin 4

这对你有用吗?

打字稿:

getHighlightColor():string {
   return  "rgba(255,255,255,1)"; 
}
shouldHighlight(): boolean {
    return true;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<td mat-cell [style.border-color]="getHighlightColor(piano[cam])" [ngClass]="{ 'highlighted': shouldHighlight(piano[cam])}"
Run Code Online (Sandbox Code Playgroud)

CSS:

.highlighted{
   border-width:3px;
   border-style:solid;
   border-color:transparent;
}
Run Code Online (Sandbox Code Playgroud)