无法在“元素”上执行“setAttribute”:“<!--[ngClass]”不是有效的属性名称

问题描述

我正在使用 angular 使用 ngFor 渲染一组列,我必须动态设置列的类和单击事件

如果传递的索引在任何设置中已经可用,那么我必须禁用该列或忽略单击事件并将列类设置为不同的值。

td 的 HTML 如下

 <td *ngFor='let colData of rowData.columns'                   
    (click)="existsInSelectedColumns(colData.colIndex) ? $event.stopPropagation() : cellClicked(colData.cell)"            
    [ngClass]="existsInSelectedColumns(colData.colIndex) ?'cell-selected':'cell-default'"
    >
  {{colData.colIndex}}-
  {{colData.cell.value}}
</td>

打字稿代码如下

  selectionSettings: ColumnSelectionSettings = {
    startIndex: -1,selections: [
      {
        type: 'Cell 1',colIndex: -1
      },{
        type: 'Cell 2',{
        type: 'Cell 3',{
        type: 'Cell 4',colIndex: -1
      } 
    ]
  };
  
  
  
  existsInSelectedColumns(selectedindex) {
    console.log(selectedindex);
    //check selectedindex is available in any of the 'colIndex' values returns true
    if(this.selectionSettings.colIndex.includes(selectedindex))
    {   
        return true;
    }
    else
    {
        return false;
    }   
  }
  

运行时出现错误

错误 DOMException:无法在“元素”上执行“setAttribute”:“

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)