簡體   English   中英

從httpclient.get獲取數據的Angular Show加載器

[英]Angular Show loader on fetching data from httpclient.get

我想知道從api提取數據時如何添加加載程序。 在數據到來之前,我需要加載程序。

this.clientData = this.httpClient.get(url,{responseType: 'json'}).
  subscribe(data => {
   //here the loader come i think
  console.log(data);
  this.data = data.records;
 }

當獲取數據時,加載器關閉。 如果可能的話,在應用程序中也使用bootstrap im。

我不知道這是否是最好的方法,但我想它會起作用

async getCall() {
  // Show loader here
  this.showLoader = true;

  this.clientData = await this.httpClient.get(url,{responseType: 'json'}).toPromise();

  // Hide Loader here
  this.showLoader = false;
}

零件

this.IsLoading = true;
    this.httpClient.get(url,{responseType: 'json'}).subscribe(
      (data: any) => {
        this.data = res.records;
        console.log(res);
      },
      error => { },
      () => (this.IsLoading = false)
    );
  }

html文件

<div class="content" [appSpinner]="IsLoading">
/*show content*/
</div>

並添加spinner作為directive

或者,如果您不想使用指令,則可以簡單地使用

<div class="content" *ngIf="IsLoading">
/***/
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM