error TS2571: Object is of type 'unknown' when try pipe slice in *ngFor

Viewed 4440

I trying to use NGB Pagination on my angular app in a table. But when i use pipe slice in my *ngFor, my Angular appear error TS2571: Object is of type 'unknown' when try slice. This is my code:

  1. My HTML code:
<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. My .ts code:
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. My Object in console: enter image description here

  2. And my Error: enter image description here

Thanks for your help!

1 Answers

Change documentaryList: any; to documentaryList: any[] = [];

Related