如何在打字稿中的箭头函数中传递参数

How to pass arguments in arrow functions in typescript

我正在尝试实现自定义管道/

   transform(value: any, id?: number, field?:string): any {
       if(value)
       {
        return value.filter(contact=>contact.ContactType===id)
       }
      }

我从 html 像这样调用它

*ngFor="let mailingContact of facilityContacts | contactFilter:1:'ContactType'"

在这里我将获取id参数中的值'1'并将其直接设置为箭头函数。但我也想用参数字段名称更改 contact.ContactType 中的 ContactType。

有什么办法可以实现吗?

您可以使用 [] 属性 访问运算符。

return value.filter(contact => contact[field] === id)