javascript - Angular2 在等待数据加载时更新 View

标签 javascript typescript angular2-template angular2-forms

我有一个表单,需要输入要求用户选择数字。 提交表单后,我希望在生成和格式化数据时显示“旋转图形”。
目前,在数据返回之前我无法显示微调器。

我的代码如下:

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;
  }

正在加载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();

关于javascript - Angular2 在等待数据加载时更新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44186689/

相关文章:

javascript - ASP.NET MVC View 中 javascript 文件的语法突出显示?

JavaScript - 错误 404 资源未找到

javascript - 使用 Angular 从下拉列表中获取选定的值

angular - [] 和 {{}} 将状态绑定(bind)到属性的区别?

angular - 尝试使用嵌套组件时 promise 未捕获的异常

Angular 5 - 通过 ngModel 从子模板组件向父组件发送错误

javascript - 如何在 IONIC2 中添加标记点击监听器?

javascript - 发布后无法设置表单属性值

javascript - 如何在组件中显示 Observables?

typescript - 如何为导出函数的节点模块编写 typescript 定义文件?