angular - 如何以编程方式显示/隐藏材料表页脚?
问题描述
有没有办法使用@Input()
变量显示/隐藏材质表页脚?我正在尝试构建一个可能有也可能没有页脚的自定义表格组件,就像这样
<my-component [showFooter]="false"></my-component>
我想到的显而易见的事情就是*ngIf
在mat-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>
推荐阅读
- discord.js - discord.js - 发送关于成员禁令的图像?
- r - R - 将多个 Docx 文件合并为单个 Docx 文件
- angular - 子组件未在 ngFor 中正确加载(但在调整窗口大小后更新)
- c++ - G++/CMake Profile Guided Optimization 找不到生成的 .gcda 文件
- asp.net - 如何更新 JSON 数组类型数据
- excel - Excel VBA 超链接地址,包括特殊字符
- python - 如何使用 Folium 更正“ValueError:无法渲染缺少任何几何图形的对象”
- python - mypy 在 Dict 外部报告错误但不在内部
- laravel - 无法让 Livewire 事件 Emit 和 Listen 工作
- python - 在 VPS 上运行本地 Python 脚本