簡體   English   中英

Angular2在等待數據加載時更新視圖

[英]Angular2 Update a View while waiting for data to load

我有一個要求輸入要求用戶選擇號碼的表格。 提交表單后,我希望在生成和格式化數據時顯示“旋轉圖形”。
目前,直到返回數據后,我才能顯示微調器。

我的代碼如下:

getTickets(){
  this.PBPicks=this._lottoService.getPBTicket(this.newTixForm.value['PBTix']);
  this.MegaPicks=this._lottoService.getMegaTicket(
  this.newTixForm.value['MegaTix']);
  return false;
 }

submitForm(){
  this.isLoading=true;
  console.log('Show Spinner');
  this.isLoading=this.getTickets();
    console.log("Data Loaded");
 }

返回並顯示數據的時間是微調器顯示然后消失的時間,即使控制台顯示該數據的執行時間比返回數據時要早得多。

這是我所做的:加載圖標組件:

isLoading = false;
   constructor() { }

   ngOnInit() {}
   show() 
  {
    this.isLoading = true;
   }
  hide() 
  {
    this.isLoading = false;
  }

Loading-icon.component.html

<span *ngIf="isLoading">
  <img src="/assets/images/loading.gif" alt="">
</span>

App.Component.ts

//To get access to component and its method, using the @ViewChild decorator
 @ViewChild('imLoading') imLoading: LoadingIconComponent;

this.model.getData = getData;
this.imLoading.show();

暫無
暫無

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

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