简体   繁体   English

Angular2-显示加载消息,并在异步调用完成后将其隐藏

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

I am willing to show/hide a Loading message once the async call from a REST API finishes, it hides the Loading message and show the fetched content instead. 一旦来自REST API的异步调用完成后,我愿意显示/隐藏“ 正在加载”消息 ,它会隐藏“ 正在加载”消息并显示取回的内容。

I don't know how to achieve that in Angular2, but in JavaScript, something like this is done: 我不知道如何在Angular2中实现这一目标,但是在JavaScript中,是这样完成的:

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

I believe you are using an ngFor to display the data fetched. 我相信您正在使用ngFor来显示获取的数据。

This should work for you: 这应该为您工作:

<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