我是角度2和离子的新手,所以我会尽量缩短它:
<ion-card class="acc-page-card" *ngFor="let account of accounts">
<ion-card-content>
<!-- Add card content here! -->
<ion-item (click)="GoTo('AccountPage')">
<div class="acc-img" item-left>
<img src="{{account.img}}" alt="">
</div>
<div class="acc-details">
<span class="name">{{account.title}}</span>
<span class="title">{{account.link}}</span>
</div>
<div class="acc-icons" item-right>
<i *ngIf="valueFromArray" class="icomoon-Add-user-icon"></i>
<i *ngIf="valueFromArray" class="icomoon-Favorites-icon"></i>
</div>
</ion-item>
</ion-card-content>
</ion-card>
其中&#39; valueFromArray&#39;是我想从循环的数组中得到的值 我试过了:
<i *ngIf="{{account.isFriend}}" class="icomoon-Add-user-icon active-icon"></i>
这是错的。 所以,如何使用数组中的值我在这样的情况下循环? 抱歉我的英语不好。
答案 0 :(得分:5)
您只需像访问其他变量一样访问它:
<i *ngIf="account.isFriend" class="icomoon-Add-user-icon active-icon"></i>
img标签的另外几行应该是:
<img [src]="account.img" alt="">
不要在内部属性中使用插值{{...}}
,只需在内容文本中使用。对于像src
这样的属性值,您应该使用输入属性绑定[attribute]=value
答案 1 :(得分:2)
尝试使用* ngIf =“account.isFriend”
<i *ngIf="account.isFriend" class="icomoon-Add-user-icon active-icon"></i>