【发布时间】:2023-03-17 09:21:01
【问题描述】:
我正在开发一个 ionic 应用程序,我在 HTML 文件中使用 *ngFor="let playerValue of players" 获取值
但是在插值{{playerValue.playerPhoto}} 或playerValue.playerType 时,我在 html 中使用 playerValue 的属性(如 playerPhoto 或 playerType)时出错
例如:-
<img src={{playerValue.playerPhoto}}></button>
或
<div *ngSwitchCase="playerValue.playerType">
错误信息是-:
[Angular] 标识符“playerType”未定义。 '' 做 不包含这样的成员
或
[Angular] 标识符“playerPhoto”未定义。 '' 做 不包含这样的成员
我得到错误的html
<ion-content no-padding>
<div class="create-team-section">
<ion-list class="team-create-list">
<div [ngSwitch]="playerType" *ngFor="let playerValue of players |
search : terms| sort: {property: column, order: order}; let i = index">
<div *ngSwitchCase="playerValue.playerType" ngSelected="selected">
<ion-item [class.active]="playerValue.isSelected? 'active' : null">
<ion-grid no-padding>
<!-- <a (click)="playerInfo()"><img src={{playerValue.playerPhoto}}></a> -->
<ion-row align-items-center [class.shake]="shake==playerValue.playerUid ? 'shake' : null">
<ion-col col-3>
<!-- <div class="create-team-imge" >
<img src={{playerValue.playerPhoto}}>
</div> -->
<div class="create-team-imge">
<ion-avatar item-star no-line>
<button (click)="playerinfo(i)"><img src={{playerValue.playerPhoto}}></button>
</ion-avatar>
<ion-badge>
<ion-icon name="information"></ion-icon>
</ion-badge>
</div>
</ion-col>
<ion-col col-md-9 col-9 (click)="setClickedRow(i)">
<ion-row align-items-center>
<ion-col col-md-8 col-7>
<p>{{playerValue.playerName}}</p>
<p>Selected By {{playerValue.selectedBy}}</p>
<p class="country" >{{playerValue.teamName}}</p>
<p class="points"> Points:
<span>{{playerValue.totalPoint}}</span>
</p>
</ion-col>
<ion-col col-md-4 col-5 class="cradit">
<p>
<span>{{playerValue.playerCreditPoint}}</span>
</p>
<button ion-button icon-only>
<ion-icon [name]="playerValue.isSelected? 'close' : 'ios-checkmark'"></ion-icon>
</button>
</ion-col>
</ion-row>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</div>
</div>
</ion-list>
</div>
</ion-content>
ts 文件
export class CreateteamPage {
players: any = [];
【问题讨论】:
-
也许先尝试删除 *ngFor 上的 '[ngSwitch]="playerType",因为它似乎正在使用您的播放器属性之一。
-
你输入
{{playerValue | json}}时会显示什么? -
playerValue是如何定义的?
-
@selemmn 它以 { "key" : "value" , "key" : "value" } 格式正确出现
-
@DelwynPinto 是在json中定义的
标签: angular ionic-framework ionic2 ionic3