Ошибка типа: this.responsearray.find не является функцией angular - PullRequest
0 голосов
/ 21 марта 2020

Я получаю приведенную ниже ошибку при попытке указать countryName в массиве ответов.

TypeError: this.responsearray.find is not a function

Вот мой код TS

Это то, что я объявил

 responsearray: any;
      editCountry(row){
        let founditem = this.responsearray.find(item => item.countryName==row);
        console.log(founditem)
        if(founditem !== undefined){
        const dialogRef = this.dialog.open(popupcomponent, {
          width: '800px',
          panelClass: 'custom-modalbox',
          disableClose: true,
          data: {pageValue:founditem}   
        });

        dialogRef.afterClosed().subscribe(result => {
          console.log('The dialog was closed');
          if (!result) {
            this.loadData();
          }
        });
      }
      }

Вот мой интерфейс

export interface assumption {
countryID: number;    
CountryName: string;
UserId: number;
UserName: string;
JoiningDate: String;
BirthDate: String;
OverallLength:number;}

Пожалуйста, дайте мне знать, что я здесь не так делаю.

Ответы [ 3 ]

1 голос
/ 21 марта 2020

Машинопись очень требовательна к типам. Вам необходимо инициализировать переменную responsearray как массив, чтобы использовать метод find().

responsearray = [];
1 голос
/ 21 марта 2020

Отсутствует тип для массива

class App {
  private responsearray: assumption[] = [];
  editCountry(row) {
    let founditem = this.responsearray.find(item => item.CountryName == row);
    if (founditem !== undefined) {
      const dialogRef = this.dialog.open(popupcomponent, {
        width: "800px",
        panelClass: "custom-modalbox",
        disableClose: true,
        data: { pageValue: founditem }
      });

      dialogRef.afterClosed().subscribe(result => {
        console.log("The dialog was closed");
        if (!result) {
          this.loadData();
        }
      });
    }
  }
}
export interface assumption {
  countryID: number;
  CountryName: string;
  UserId: number;
  UserName: string;
  JoiningDate: String;
  BirthDate: String;
  OverallLength: number;
}
1 голос
/ 21 марта 2020

responsearray должно быть Array и, пожалуйста, инициируйте it.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...