在加载之前在视图中加载数据 [英] load data in the view before loading it

查看:12
本文介绍了在加载之前在视图中加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我正在使用 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

template: `
 <div *ngIf="data">
   ... <!-- content -->
 </div>`

设置data时,会显示内容.

您还可以使用安全导航或 Elvis 运算符来避免错误消息

You can also use the safe-navigation or Elvis operator to avoid error messages

template: `<div>{{data?.someProp}}</div>`

datanull

这篇关于在加载之前在视图中加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆