在加载数据之前在视图中加载数据 [英] load data in the view before loading it
本文介绍了在加载数据之前在视图中加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,我正在使用Ionic 2和angular 2。
I have a problem, I am working with Ionic 2 and angular 2.
我必须在视图中显示一些数据,但我从API获取这些数据在同一页面中,所以当我尝试在视图中显示它们时,它们尚未定义。获取这些数据后如何等待加载视图?
I have to show some datas in a view but I get these datas from an API in the same page so when I try to show them in the view, they are undefined yet. How can I wait to load the view after getting these datas?
我试过onPageWillEnter但它不起作用。
I have tried onPageWillEnter but it does not work.
提前谢谢。
推荐答案
您可以使用 * ngIf $包装模板c $ c>
template: `
<div *ngIf="data">
... <!-- content -->
</div>`
当数据
已设置,将显示内容。
When data
is set, the content will be shown.
您还可以使用安全导航或Elvis运算符来避免错误消息
You can also use the safe-navigation or Elvis operator to avoid error messages
template: `<div>{{data?.someProp}}</div>`
以避免在数据
null
这篇关于在加载数据之前在视图中加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文