gpt4 book ai didi

angular - 如何以编程方式显示/隐藏 Material 表页脚?

转载 作者:行者123 更新时间:2023-12-04 11:52:06 26 4
gpt4 key购买 nike

有没有办法使用 @Input() 显示/隐藏 Material 表页脚多变的?我正在尝试构建一个自定义表格组件,它可能有也可能没有页脚,就像这样

<my-component [showFooter]="false"></my-component>

我想到的显而易见的事情就是放一个 *ngIfmat-footer-row在组件定义中。但是当我尝试使用
<tr *ngIf="showFooter" *matFooterRowDef="displayedColumns; sticky: true"></tr>

或者
<td *ngIf="showFooter" mat-footer-cell *matFooterCellDef>{{someValue}}</td>

我从编译器收到以下错误。
Can't have multiple template bindings on one element. Use only one attribute prefixed with *

如果我无法使用 *ngIf 实现它,那么实现它的正确方法是什么? ?

最佳答案

您只能在单个元素上使用一个结构指令(用 * 表示)。

您可以使用 ng-container :

<ng-container *ngIf="showFooter">
<td mat-footer-cell *matFooterCellDef>{{someValue}}</td>
</ng-container>

关于angular - 如何以编程方式显示/隐藏 Material 表页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58429016/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com