1
我有一個表組件:Angular 2,我應該採取哪種方法來顯示加載指示?
@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-頁,我需要從服務器獲取數據,所以我做通過服務的http請求,比方說page.service.ts。在這一刻,我想在我的ag表中顯示加載指示。
哪種方法最好?
使用@ViewChild通過ag-page獲取組件實例並將isLoading設置爲true?
創建一個table.service.ts,將它注入到TableComponent並使用observables來檢測數據何時加載。
另一個建議?
有趣的是,它太簡單了,我想我只能以這些複雜的方式來做到這一點...當我在ag頁面中點擊刷新數據按鈕時,我需要設置this.rows = undefined;再次重複這個過程吧? –
是的,如果你想添加一個刷新按鈕,你只需要'刪除this.rows'或'this.rows = null'或類似的東西。我只是意識到你可以做到這一點更容易(我已經做了編輯) –
不要忘記驗證答案,如果它滿足你的需要。 –