You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PrimeNG删除函数报错:Films类型无filter属性及隐式any类型问题

问题解决方法

错误原因及修复步骤

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

filter是数组的内置方法,你当前把组件中的this.films声明成了单个Films对象类型,而非数组类型。需要将this.films的类型修正为Films[]:

在组件类中定义:

films: Films[] = []; // 确保是数组类型,而非单个对象

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

TypeScript要求明确标注类型,filter回调函数的参数val没有指定类型,导致隐式any报错。给val加上Films类型即可:

完整修正后的deleteFilm方法

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: Films) => val.id !== film.id);
      this.film = {};
      this.messageService.add({ severity: 'success', summary: 'Successful', detail: 'Product Deleted', life: 3000 });
    }
  });
}

内容的提问来源于stack exchange,提问作者Kerk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 19:30:38