我试图使用垫表在我的Angular 15 <tr mat-footer-row *matFooterRowDef="displayedColumns"></tr>
在正确的位置在底部,和displayedColumns是工作的其他表部分我得到这个错误
Cannot read properties of undefined (reading 'template')
at MatFooterRowDef.extractCellTemplate (table.mjs:415:38)
at table.mjs:1904:27
在使用此功能时,我还需要添加/删除/导入哪些内容?我已导入MatTableModule
厌倦了棱角分明的Mat文档只是合法地错误和没有解释.
文件:ts
@Component({
selector: 'saa-prior-sales',
templateUrl: './prior-sales.component.html',
styleUrls: ['./prior-sales.component.css'],
standalone: true,
imports: [CommonModule, CurrencyPipe, MatTableModule],
})
export class PriorSalesComponent implements OnChanges {
@Input() sales?: IVehicleDetails[]; //New Interface for Sale
//Sort these in descending Date (table cannot be sorted)
dataSource = new MatTableDataSource<IVehicleDetails[]>();
displayedColumns: string[] = [
'model',
'style',
'eng',
'trans',
'miles',
'price',
'date',
];
ngOnChanges(changes: SimpleChanges) {
const vehicleList = changes['sales'].currentValue;
this.dataSource = vehicleList;
}
}
超文本标记语言
<div
*ngIf="dataSource"
class="w-full p-6 mt-0 bg-white border border-gray-200 rounded-lg shadow md:mb-4 sm:mb-4 ng-star-inserted saa-green">
<div class="p-2 mb-4 text-xl font-medium saa-blue">Prior Sales</div>
<table mat-table [dataSource]="dataSource">
<!-- Location -->
<ng-container matColumnDef="model">
<th mat-header-cell *matHeaderCellDef>Model</th>
<td mat-cell *matCellDef="let sale">
{{ sale.vehicle?.location }}
</td>
</ng-container>
<!-- LaneLot Column -->
<ng-container matColumnDef="style">
<th mat-header-cell *matHeaderCellDef>Style</th>
<td mat-cell *matCellDef="let sale">{{ sale.lane }}/{{ sale.lot }}</td>
</ng-container>
<!-- VIN Column -->
<ng-container matColumnDef="eng">
<th mat-header-cell *matHeaderCellDef>Eng</th>
<td mat-cell *matCellDef="let sale">
{{ sale.eng }}
</td>
</ng-container>
<!-- VIN Column -->
<ng-container matColumnDef="trans">
<th mat-header-cell *matHeaderCellDef>Trans</th>
<td mat-cell *matCellDef="let sale">
{{ sale.eng }}
</td>
</ng-container>
<!-- VIN Column -->
<ng-container matColumnDef="miles">
<th mat-header-cell *matHeaderCellDef>Miles</th>
<td mat-cell *matCellDef="let sale">
{{ sale.eng }}
</td>
</ng-container>
<!-- VIN Column -->
<ng-container matColumnDef="price">
<th mat-header-cell *matHeaderCellDef>Price</th>
<td mat-cell *matCellDef="let sale">
{{ sale.eng }}
</td>
</ng-container>
<!-- VIN Column -->
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef>Date</th>
<td mat-cell *matCellDef="let sale">
{{ sale.date | date }}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let element; columns: displayedColumns"></tr>
<tr mat-footer-row *matFooterRowDef="displayedColumns"></tr>
</table>
</div>
如果我go 掉垫脚排,只要我补充说它坏了,它就会起作用