简体   繁体   English

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

[英]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.

相关问题 未定义标识符“ X”。 “ Y”不包含此类成员Angular - Identifier 'X' is not defined. 'Y' does not contain such a member Angular 未定义标识符“标题”。 &#39;{}&#39; 不包含这样的成员 angular 8 - Identifier 'title' is not defined. '{}' does not contain such a member angular 8 已解决 Angular 标识符“标题”未定义。 'Movie[]' 不包含这样的成员 - Solved Angular Identifier 'title' is not defined. 'Movie[]' does not contain such a member 未定义标识符“ ...”。 &#39;__type&#39;不包含这样的成员Angular FormArray - Identifier '…' is not defined. '__type' does not contain such a member Angular FormArray Angular:标识符“标题”未定义。 'never' 不包含这样的成员。 异常问题 - Angular: Identifier 'title' is not defined. 'never' does not contain such a member. Unusual problem 未定义标识符“长度”。 &#39;null&#39; 不包含这样的成员 ng(0) - Identifier 'length' is not defined. 'null' does not contain such a member ng(0) 未定义标识符“必需”。 &#39;__type&#39; 不包含这样的成员 - Identifier 'required' is not defined. '__type' does not contain such a member 未定义标识符“名称”。 “对象”不包含这样的成员 - Identifier 'name' is not defined. 'object' does not contain such a member 标识符“图像”未定义。 'never' 不包含这样的成员 - Identifier 'image' is not defined. 'never' does not contain such a member 未定义标识符“X”。 'Y' 不包含这样的成员 - Identifier 'X' is not defined. 'Y' does not contain such a member
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM