首页 > 解决方案 > 我收到错误 TS2339:任何类型 [] 上不存在属性“总​​计”

问题描述

这是片段。请帮我解决一下这个。

 response: any[] = [];
proResponse: any[] = [];


 erase(res: any[]): void {res.length = 0; this.response.total = 0; }


 onSubmit(searchForm: FormGroup) {

       this.showNhide = true;
       this.proResponse = [];
       this.proName = '';
       this.searchService.searchNResult(searchForm.value).subscribe((result: any[]) => {
      console.log('Result comes' + result.toString());
      this.response = result;
    }, (error: any) => {
      console.log('search result Loading Error :' + error);
    });
  }

标签: angulartypescript

解决方案


它应该是anynot的响应类型。any[]它应该如下,

this.searchService.searchNResult(searchForm.value).subscribe((result: any) => {
      console.log('Result comes' + result.toString());
      this.response = result;
    }, (error: any) => {
      console.log('search result Loading Error :' + error);
});

推荐阅读