Angular Can';一个元素上没有多个模板绑定。仅使用一个前缀为*(";<;/mat header cell>;
我得到以下错误:Angular Can';一个元素上没有多个模板绑定。仅使用一个前缀为*(";<;/mat header cell>;,angular,angular-material,material-table,Angular,Angular Material,Material Table,我得到以下错误: ERROR in Can't have multiple template bindings on one element. Use only one attribute prefixed with * (" </mat-header-cell> <mat-cell *matCellDef="let order" class="{{orderColumn.fi
ERROR in Can't have multiple template bindings on one element. Use only one attribute prefixed with * (" </mat-header-cell>
<mat-cell *matCellDef="let order" class="{{orderColumn.fieldClass}}" [ERROR ->]*ngIf="orderColumn.fieldType == 'date'">{{order[orderColumn.fieldName] | date: globalDateFormat}}</ma")
Can't have multiple template bindings on one element. Use only one attribute prefixed with * ("ateFormat}}</mat-cell><mat-cell *matCellDef="let order" class="{{orderColumn.fieldClass}}" [ERROR ->]*ngIf="orderColumn.fieldType == 'text'">{{order[orderColumn.fieldName]}}</mat-cell>
中的错误不能在一个元素上有多个模板绑定。只能使用一个前缀为*(“
]*ngIf=“orderColumn.fieldType=='date'>{{order[orderColumn.fieldName]|日期:globalDateFormat}}{{order[orderColumn.fieldName]}
代码如下:
<mat-table #table [dataSource]="dataSource" matSort #sort1="matSort"
matSortActive="id" matSortDirection="asc" matSortDisableClear>
<!-- Checkbox Column -->
<ng-container matColumnDef="row">
<mat-header-cell *matHeaderCellDef class="mat-column-checkbox">
Row
</mat-header-cell>
<mat-cell *matCellDef="let row" class="mat-column-checkbox">
1
</mat-cell>
</ng-container>
<ng-container *ngFor="let orderColumn of newOrderColumns;" matColumnDef="orderColumn.fieldName">
<mat-header-cell *matHeaderCellDef mat-sort-header class="{{orderColumn.fieldClass}}">{{orderColumn.fieldLable}}
</mat-header-cell>
<mat-cell *matCellDef="let order" class="{{orderColumn.fieldClass}}" *ngIf="orderColumn.fieldType == 'date'">{{order[orderColumn.fieldName] | date: globalDateFormat}}</mat-cell>
<mat-cell *matCellDef="let order" class="{{orderColumn.fieldClass}}" *ngIf="orderColumn.fieldType == 'text'">{{order[orderColumn.fieldName]}}</mat-cell>
<mat-cell *matCellDef="let order" class="{{orderColumn.fieldClass}}" *ngIf="orderColumn.fieldType == 'Checkbox'">
<mat-checkbox (click)="$event.stopPropagation()"
[checked]="order[orderColumn.fieldName] == 'True'" [color]="'primary'">
</mat-checkbox>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>
一行
1.
{{orderColumn.fieldLable}
{{order[orderColumn.fieldName]|日期:globalDateFormat}
{{order[orderColumn.fieldName]}
请帮助我如何解决此问题。一个元素上不能有多个模板绑定。*matCellDef和*ngIf是结构指令,不能在matcell中同时使用 您可以通过使用span或任何其他元素包装该元素来构建该元素。例如,您可以尝试以下操作:
<ng-container *ngIf="orderColumn.fieldType == 'date'">
<mat-cell *matCellDef="let order" class="{{orderColumn.fieldClass}}">
{{order[orderColumn.fieldName] | date: globalDateFormat}}</mat-cell>
</ng-container>
{{order[orderColumn.fieldName]|日期:globalDateFormat}
尝试在这些单元格上使用
[hidden]
而不是ngIf
。您不能同时使用mafCellDef和ngIf,您可以在ng容器上使用ngIf,并将mat cell放在该容器内。我同意@piyus,使用ng container
并将您的*ngIf
放在那里。