【发布时间】:2018-01-21 17:41:38
【问题描述】:
我正在尝试制作一个读取 WP-API 的简单应用程序。我的问题是,如果帖子没有特色图片,则变量变为“null”,然后应用程序崩溃。这是我的代码
<ion-card *ngFor="let post of posts" (click)="onSelectPost(post)">
<img [src]="post.better_featured_image.source_url"/> \\Here is the problem
<ion-card-content>
<ion-card-title>
{{post.title.rendered}}
</ion-card-title>
<p [innerHtml]="post.excerpt.rendered"></p>
</ion-card-content>
有什么方法可以检查变量是否为空然后隐藏它?
【问题讨论】:
-
*ngIf 是你的朋友。 angular.io/guide/template-syntax#ngif
-
@vais 标记如果答案有帮助
标签: angular ionic-framework ionic3