[英]Angular Identifier 'playerType' is not defined. '' does not contain such a member
I am working on an ionic app, where I am fetching value using *ngFor="let playerValue of players"
, in HTML file 我正在开发一个离子应用程序,使用HTML文件中的
*ngFor="let playerValue of players"
获取值
But I am getting error on using property of playerValue like playerPhoto or playerType in html while interpolation {{playerValue.playerPhoto}}
or playerValue.playerType
eg : - 但是我在插值
{{playerValue.playerPhoto}}
或playerValue.playerType
html中的playerValue或playerType之类的playerValue的属性时遇到错误,例如:-
<img src={{playerValue.playerPhoto}}></button>
or 要么
<div *ngSwitchCase="playerValue.playerType">
error message is -: 错误消息是-:
[Angular] Identifier 'playerType' is not defined.
[角度]标识符'playerType'未定义。 '' does not contain such a member
''不包含这样的成员
or 要么
[Angular] Identifier 'playerPhoto' is not defined.
[角度]标识符'playerPhoto'未定义。 '' does not contain such a member
''不包含这样的成员
html where I am getting the error 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 file ts文件
export class CreateteamPage {
players: any = [];
Try creating an interface like this 尝试创建这样的界面
export interface Players {
playerType: string;
playerPhoto: string;
}
And in your ts file: 并在您的ts文件中:
import { Players } from './models/players' // path to the interface
export class CreateteamPage {
players: Players[];
// rest of the code
}
Try safe parameter ?
尝试安全参数
?
: :
<img src={{playerValue?.playerPhoto}}></button>
And 和
<div *ngSwitchCase="playerValue?.playerType">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.