我想在Angular中向浏览器显示一个简单的数据,但是一旦所有数据都从服务中检索,我想显示数据。不要加载页面,直到所有数据都从服务中检索
如何做到这一点?
目前即使没有完成获取我的数据,页面也会显示。
下面是示例代码
In test.component.ts file
ngOnInit() {
this._service.getQuestions().subscribe(data => { this.questionCollection = data });
}
在我的服务
getQuestions() {
return this._http.get('assets/questions.json')
.map(res => res.json())
.catch(this.handleError);
}
.html文件
<div> Other text here...... </div>
<div *ngFor="let col of questionCollection">
<button type="button" class="btn btn-default">{{col.Text}}</button>
</div>
你想要发生什么?要加载的路线,要显示的加载指标,还是列表不显示?显示更多组件代码也可能有所帮助 – Fiddles
如果要在导出数据之前阻止导航,可以使用auth警卫返回可观察值。 – 2017-05-24 05:07:04