angular - how to dynamically show a mat-progress-bar when a button is clicked
问题描述
Hi I am have about 6000 rows of data I am filtering in my mat-table that takes about 5 seconds to filter when a "Filter" button is clicked. I am trying to show a Mat-Progress-Bar while the function is being called. I have attached a sample stackblitz to try and repro my problem. I want the Mat-Progress-Bar to only show when the "Filter" button is clicked and disappear when the the data is renderded.
https://stackblitz.com/edit/angular-4ttand-8ckvs7?file=src/app/table-basic-flex-example.ts
<button mat-raised-button (click)="filterTable()"> Filter Table on Weight!</button>
<mat-progress-bar *ngIf="isLoading" color="primary" mode="indeterminate"></mat-progress-bar>
export class TableBasicFlexExample {
isLoading = true
filterTable() {
this.dataSource = this.dataSource.filter((item) => {
return Math.floor(item.weight) > 10});
this.isLoading = false;
}
}
解决方案
Try this.
https://stackblitz.com/edit/angular-4ttand-i6mwao?file=src/app/table-basic-flex-example.ts
PS: Don't forget to delete setTimeout, I used it to "simulate" the time it takes your function to filter.
filterTable() {
this.isLoading = true
this.dataSource = this.dataSource.filter((item) => {
console.log(Math.floor(item.weight));
return Math.floor(item.weight) > 10});
this.isLoading = false;
}
推荐阅读
- httpd.conf - 即使在应用程序部署之后,如何永久编辑 httpd.conf 以使 apache 2.4 中的更改发生?
- c++ - 为 Sublime Text 的 g++ 构建和运行设置超时?
- android - 如何在 Android 的改造 Body 中仅发布 Array
- javascript - 无法在节点 API 中获取请求正文
- mongodb - 应用聚合时在 Mongo Scala 驱动程序中出现盒装错误
- jquery - 如何检测笔记本电脑触控板上的单次滑动
- bots - 如何批量删除特定频道?
- r - 在数据框中包含必填列
- excel - 在某些 csv 文件不存在时读取其他 csv 文件名
- json - 在 Chrome 上以 JSON 格式获取 API 响应,在 Firefox 上在 application/x-gzip 中获取 API 响应