我有一个表格组件:
@Component({
moduleId: module.id,
selector: 'ag-table',
template: `
<span *ngIf="isLoading">Loading</span>
<table class="table">
rows loaded through @Input() rows;
</table>
`
})
然后我有一个父组件:
@Component({
moduleId: module.id,
selector: 'ag-page',
template: `
<ag-table [rows]=rows></ag-table>
`
})
现在,在 ag-page 中,我需要从服务器获取数据,所以我通过服务发出 http 请求,比如说 page.service.ts。此时,我想在我的 ag 表中显示加载指示。
哪个是最好的方法?
使用@ViewChild 通过ag-page 获取组件实例并将isLoading 设置为true?
创建一个 table.service.ts,将其注入 TableComponent 并使用 observables 来检测数据何时加载。
另一个建议?