我正在使用PrimeNg表来显示数据,并添加了如下空消息模板:
<ng-template pTemplate="emptymessage">
<tr>
<td>
No records found
</td>
</tr>
</ng-template>
并且我正在使用延迟加载,因为数据是从服务器获取的。我添加了一个加载标志,当http调用完成时,它会被更改。代码如下:
this.myService
.myHttpCallFunction(params)
.pipe(
finalize(() =>{ this.loading = false;}, 100)
)
.subscribe(
(result: JsendResponse) => this.data = result.data,
errors => this.errors = errors
);
我将loading
标志传递给表,它看起来如下:
<p-table [value]="data?.data" [columns]="settings.columns" [loading]="loading">
现在它显示加载图标一段时间,然后显示空消息一段时间。然后只有它会显示实际数据。这实际上是令人困惑的,因为用户可能会认为没有数据,因为它显示的是空消息。
像下面的一样更新您的代码
this.myService
.myHttpCallFunction(params)
.subscribe(
(result: JsendResponse) => {
this.data = result.data;
this.loading = false;
},
errors => this.errors = errors
);