簡體   English   中英

Angular2-顯示加載消息,並在異步調用完成后將其隱藏

[英]Angular2 - Show a loading message, and hide it once the async call finishes

一旦來自REST API的異步調用完成后,我願意顯示/隱藏“ 正在加載”消息 ,它會隱藏“ 正在加載”消息並顯示取回的內容。

我不知道如何在Angular2中實現這一目標,但是在JavaScript中,是這樣完成的:

 <h2 id="message">Loading....</h2>
 <script>
 $(document).ready(function(){
  $('#message').hide();
   //Then Show the newly fetched content
  }
 </script>

我相信您正在使用ngFor來顯示獲取的數據。

這應該為您工作:

<div *ngIf="!content">Loading...</div>
<div #ngFor="#content of content"></div>
<div *ngIf="content">Now the fetched content appears here!</div>
<div *ngIf="!content">Loading...</div>
<div *ngIf="content"> TODO display the content here </div>

暫無
暫無

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

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