2017-05-25 52 views
0

我有一个需要输入的表单,要求用户输入要选择的数字。 提交表单时,我想要在生成和格式化数据时显示“微调图形”。
此刻,我无法让微调器显示,直到数据返回。Angular2在等待数据加载时更新视图

我的代码如下所示:

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

当返回和显示的数据是微调显示了当,然后消失,即使控制台显示它正在返回数据时相比,更快执行。

+1

如何纳克-模板? – Bruno

+0

这可能是一个更改检测问题。分享一些更多的代码,我们可能肯定知道。 – Chrillewoodz

回答

2

这里是我做过什么: 加载图标组成:

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();