angular - 如何在打字稿中的箭头函数中传递参数
问题描述
我正在尝试实现自定义管道/
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)
推荐阅读
- php - 由于可能的配置错误,限制 10 个内部重定向
- java - 使用 Map 填充 Java 对象
- java - 钻石运算符建议,但导致错误
- php - 在 Linux 中的 php 中显式超时文件读取 I/O 操作?
- python - 使用 Python 和 Pandas 从 Confluence REST 中检索页面内容
- vue.js - Vuex getter 不返回当前状态值
- python - Python 类成员访问
- c - 当我只有指向该结构的指针时,如何访问保存在结构中的字符串中的单个字符
- react-native - 如何使用 react-native 和 expo 获取位于 assets 文件夹中的文件的绝对路径?
- regex - Command To Find Out If a HKEY_USER Path Exists