类型错误,Angular 5:无法读取属性'length'

时间:2018-06-08 18:39:47

标签: angular html5 typescript

我仍然遇到以下错误: 类型错误无法读取属性'length',连接到html第9行:

           测试

    observeEvent(
        {
        ### Observe the download handler preparing for CSV download
        output$Wire_Centers.csv <- downloadHandler(
            filename = "Wire_Centers.csv",
            content = function(file) {
                write.table(WC_List_2(), file, row.names=FALSE, col.names = TRUE, sep=',') ### end write.table
                } # End content function
            ) # End downloadHandler
            }, { # End observered event, start log
        logUse("WC_Download")
        }) # end observeEvent output condition

来自组件的checkIfTrue:

</mat-header-cell>
          <mat-cell fxFlex="40%" mat-cell *matCellDef="let row; let element"
  line 9:    [ngStyle]="checkIfTrue(element.name) && {'background-color':'lightgreen'}">
          <mat-checkbox [ngStyle]="checkIfTrue(element.name) && {'background-color':'white'}" (click)="$event.stopPropagation()" (change)="$event ? selection.toggle(row) : null" [checked]="selection.isSelected(row)">
          </mat-checkbox>
          </mat-cell>
  </ng-container> 

我认为,所有值都已初始化。

1 个答案:

答案 0 :(得分:1)

因为未在html中定义element.name会导致错误并且即使将其更改为元素也不起作用?.name,您可以执行以下操作:

<mat-cell *ngIf="element.name" fxFlex="40%" mat-cell *matCellDef="let row; let element"
[ngStyle]="checkIfTrue(element.name) && {'background-color':'lightgreen'}">