错误 TS2571:在 *ngFor 中尝试管道切片时,对象的类型为“未知”

时间:2021-07-26 15:17:45

标签: html angular typescript

我尝试在表格中的 angular 应用程序上使用 NGB 分页。但是当我在 *ngFor 中使用管道切片时,我的 Angular 在尝试切片时出现错误 TS2571: Object is of type 'unknown'。这是我的代码:

  1. 我的 HTML 代码:
<tr *ngFor="let row of documentaryList|slice: (page-1) * pageSize : page * pageSize" class="text-md text-md-center">
                  <td>{{ row.documentDate }}</td>
                  <td><a class="text-info" routerLink="details-documentary/{{row._id}}">{{ row.documentName }}</a></td>
                  <td>{{ row.documentNumber }}</td>
                  <td>{{ row.documentType }}</td>
                  <td>{{ row.documentAddress }}</td>
                  <td>
                    
  1. 我的 .ts 代码:
export class ListDocumentaryComponent implements OnInit {
  title = 'Documentary';
  documentaryList: any;
  page = 1;
  pageSize = 10;
  lengthDocumentList = 0;

  constructor(private documentaryService: DocumentaryService) {
  }

  ngOnInit(): void {
    this.getDocumentaryList();
  }

  getDocumentaryList(): any {
    this.documentaryService.getDocumentary()
      .subscribe((data: any) => {
        this.documentaryList = data.data;
        this.lengthDocumentList = this.documentaryList.length;
      });
  }

}
  1. 控制台中的我的对象: enter image description here

  2. 还有我的错误: enter image description here

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

documentaryList: any; 改为 documentaryList: any[] = [];