angular - 使用 ngIf 时 mat-paginator 不显示数据
问题描述
我的 HTML 中有以下代码。
<div *ngIf="schemaStatus" class="new-popups">
<ng-container>
My grid code
</ng-container>
<div class="mdl-grid pull-right">
<mat-paginator id="paginator{{pageSize}}" (page)="setPagination()" [pageSizeOptions]="pagination.pageSizeOptions" [pageSize]="pageSize"></mat-paginator>
</div>
</div>
在角度 ts 文件中,我编写了以下代码
@ViewChild(MatPaginator) paginator: MatPaginator;
如果我将schemaStatus
变量值从true
to更改为false
,则我的分页显示 0 值。false
true
- 在我从 更改
schemaStatus
为true
之前false
。
- 在我
schemaStatus
从true
tofalse
和 back to改变之后true
。
如何让分页器显示数据?
解决方案
我有同样的错误。我通过将 @ViewChild 更改为 setter 来解决它。这意味着每当您的分页器将被新初始化时,数据源都会获得新的分页器。将静态属性设置为 false 很重要,因为它并不总是存在。
@ViewChild(MatPaginator, {static: false}) set paginator(value: MatPaginator) {
if(this.dataSource) {
this.dataSource.paginator = value;
}
}
推荐阅读
- visual-studio-code - 无法在片段中获得建议
- javascript - Firebase Cloud Messaging - 在发送通知之前获取数据?
- opencv - 有没有任何方法可以在不从 Unity 资产商店购买 EmguCV 包的情况下将 EmguCV 与 Unity 一起用于 UWP(HoloLens)应用程序开发?
- javascript - 通过特殊字符从字符串中查找并提取序列
- angular - 本机脚本 DatePicker 显示错误的月份值
- angular - 在 html 中使用异步管道 => ¿BehaviorSubject 或 Observable?
- time - 标签到轴 - 将 int(秒)转换为小时
- entity-framework - 尝试实体框架代码优先;用法与 Database-first 有什么不同吗?
- python-3.x - 僵尸袭击村庄,蟒蛇
- javascript - R plotly:如何通过带有多个图的图例单击来观察跟踪是隐藏还是显示