根据我的理解,只需要对链进行一次安全检查
?.
,这样你就可以简化代码。
<div *ngFor="let table of invData.tables;trackBy: utilServ.trackByFnIndex"> <!-- removed ?. because tables will not be undefined as per the interface! -->
<table>
<thead *ngIf="invData?.columns?.[table]?.length > 0"></thead> <!-- will safe check the sequence and prevent any undefined errors -->
</table>
</div>