Angular 对于,将多参数函数传递给管道
我正在使用此链接的“where”管道: 可与以下功能一起使用:Angular 对于,将多参数函数传递给管道,angular,function,pipe,parameter-passing,Angular,Function,Pipe,Parameter Passing,我正在使用此链接的“where”管道: 可与以下功能一起使用: const values = [{ a: 1, c: { d: 3, e: { f: 4 } } }, { a: 2, c: { d: 4, e: { f: 5 } } }]; const numbers = [1, 2, 3, 4, 1,
const values = [{
a: 1,
c: {
d: 3,
e: {
f: 4
}
}
}, {
a: 2,
c: {
d: 4,
e: {
f: 5
}
}
}];
const numbers = [1, 2, 3, 4, 1, 4];
// ...
aEqualsOne(item) {
return item.a === 1;
}
//usage example :
{{ values | where: aEqualsOne }} <!-- [{ a: 1, c: { d: 3, e: { f: 4 } }] -->
但我必须修改函数以接受另一个参数:
checkNum(num, k) {
console.log(num + " > " + k + "?");
return num > k;
}
问题是我找不到方法将列表项和“k”传递给传递给管道的函数:
我试过:
<card *ngFor="let num of listOfNum | where: checkNum(k)></card>
<card *ngFor="let num of listOfNum | where: checkNum(num, k)></card>
但是现在还没有成功
我该怎么办?修改:
<card *ngFor="let num of listOfNum | where: checkNum(k)></card>
不工作:(从函数checkNum的日志来看,'k'值似乎是某种索引(从0到列表长度)“我必须修改函数以接受另一个参数”,或者您创建一个从其他地方获取该值的函数。
<card *ngFor="let num of listOfNum | where: checkNum(k)></card>
<card *ngFor="let num of listOfNum | where: checkNum(num, k)></card>
<card *ngFor="let num of listOfNum | where: checkNum(k)></card>
<card *ngFor="let num of listOfNum | where: checkNum : k></card>