我试图在object
的{{1}}内显示所有数据。
但是我无法展示其中任何一个,为什么?
这是我试过的
演示:https://stackblitz.com/edit/ionic-dsdjvp?file=pages%2Fhome%2Fhome.ts
home.html的
array
home.ts
<div *ngIf="searchResults.length > 0">
<ion-item *ngFor="let searchResult of searchResults.details">
<ion-avatar item-start>
<!--<img src="img/Rabbit-Cage.jpg"> -->
</ion-avatar>
<h2>searchResult.user_id</h2>
<h3>searchResult.email</h3>
<p>searchResult.token</p>
</ion-item>
</div>
这是我的演示 https://stackblitz.com/edit/ionic-dsdjvp?file=pages%2Fhome%2Fhome.ts
请提前帮助我!
答案 0 :(得分:0)
你在这里做错了searchResults.length > 0
。您需要像searchResults?.details?.length > 0
这是工作stackblitz
<div *ngIf="searchResults?.details?.length > 0">
<ion-item *ngFor="let searchResult of searchResults?.details">
<ion-avatar item-start>
<!--<img src="img/Rabbit-Cage.jpg"> -->
</ion-avatar>
<h2>searchResult.user_id</h2>
<h3>searchResult.email</h3>
<p>searchResult.token</p>
</ion-item>
</div>
或强>
没有*ngIf
<div>
<ion-item *ngFor="let searchResult of searchResults?.details">
<ion-avatar item-start>
<!--<img src="img/Rabbit-Cage.jpg"> -->
</ion-avatar>
<h2>searchResult.user_id</h2>
<h3>searchResult.email</h3>
<p>searchResult.token</p>
</ion-item>
</div>