繁体   English   中英

未定义角度标识符“ playerType”。 ''不包含这样的成员

[英]Angular Identifier 'playerType' is not defined. '' does not contain such a member

我正在开发一个离子应用程序,使用HTML文件中的*ngFor="let playerValue of players"获取值

但是我在插值{{playerValue.playerPhoto}}playerValue.playerType html中的playerValue或playerType之类的playerValue的属性时遇到错误,例如:-

<img src={{playerValue.playerPhoto}}></button> 

要么

<div *ngSwitchCase="playerValue.playerType">

错误消息是-:

[角度]标识符'playerType'未定义。 ''不包含这样的成员

要么

[角度]标识符'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 = [];

尝试创建这样的界面

export interface Players {
 playerType: string;
 playerPhoto: string;
}

并在您的ts文件中:

import { Players } from './models/players' // path to the interface

export class CreateteamPage {

 players: Players[];

 // rest of the code
}

尝试安全参数?

<img src={{playerValue?.playerPhoto}}></button> 

<div *ngSwitchCase="playerValue?.playerType">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM