【问题标题】:TypeError: this.responsearray.find is not a function angularTypeError:this.responsearray.find 不是函数 angular
【发布时间】:2020-03-21 15:47:44
【问题描述】:

尝试在响应数组中输入 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;}

请让我知道我在这里做错了什么。

【问题讨论】:

    标签: angular angular8


    【解决方案1】:

    responsearray 应该是 Array 并且请 initiate 它。

    【讨论】:

      【解决方案2】:

      Typescript 对类型很挑剔。您需要将responsearray 变量初始化为一个数组,以在其上使用find() 方法。

      responsearray = [];
      

      【讨论】:

        【解决方案3】:

        数组缺少类型

        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;
        }
        

        【讨论】:

          猜你喜欢
          • 2020-01-10
          • 2015-09-01
          • 2018-03-19
          • 2018-07-05
          • 1970-01-01
          • 1970-01-01
          • 2018-12-16
          • 2019-07-09
          相关资源
          最近更新 更多