I am working on an ionic app, where I am fetching value using *ngFor="let playerValue of players"
, in HTML file
But I am getting error on using property of playerValue like playerPhoto or playerType in html while interpolation {{playerValue.playerPhoto}}
or playerValue.playerType
eg : -
<img src={{playerValue.playerPhoto}}></button>
or
<div *ngSwitchCase="playerValue.playerType">
error message is -:
[Angular] Identifier 'playerType' is not defined. '' does not contain such a member
or
[Angular] Identifier 'playerPhoto' is not defined. '' does not contain such a member
html where I am getting the error
<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
export class CreateteamPage {
players: any = [];
Try creating an interface like this
export interface Players {
playerType: string;
playerPhoto: string;
}
And in your ts file:
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">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.