【问题标题】:Why am I recieving this error: Property 'filter' does not exist on type 'Films'为什么我会收到此错误:属性 \'filter\' 在类型 \'Films\' 上不存在
【发布时间】:2022-12-13 03:58:05
【问题描述】:

我试图让 PrimeNG 在我的应用程序中工作,但我遇到了一个错误,我找不到解决方案来修复。

我想用 confirmationDialog 创建一个删除函数。

这是我的 component.ts 文件中的代码:

 deleteFilm(film: Films) {
    this.confirmationService.confirm({
      message: 'Are you sure you want to delete ' + film.nameOfFilm + '?',
      header: 'Confirm',
      icon: 'pi pi-exclamation-triangle',
      accept: () => {
        this.films = this.films.filter(val => val.id !== film.id);  // error is here on filter
        this.film = {};
        this.messageService.add({ severity: 'success', summary: 'Successful', detail: 'Product Deleted', life: 3000 });
      }
    });
  }

这是错误:

Property 'filter' does not exist on type 'Films'.

 Parameter 'val' implicitly has an 'any' type.

我感谢任何帮助。

【问题讨论】:

  • Films 是数组类型的别名还是该类型实现了名为filter 的函数?我们需要看看它的定义。

标签: angular primeng


【解决方案1】:

您收到此错误是因为 filterarray 原型的方法,而 filmsFilms 类型,而不是 Film[] 。如果不查看其余代码,特别是 Films 类的详细信息,就不可能提出更好的解决方案。

【讨论】:

    猜你喜欢
    • 2021-01-22
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    相关资源
    最近更新 更多