【发布时间】:2017-01-25 18:38:55
【问题描述】:
这是代码:
<div *ngFor="let product of products | mypipe : product.productColor">
<label>{{product.productName}}</label>
</div>
是否可以将产品颜色发送到管道?在控制台上打印时我得到undefined。
我已经尝试通过 interpolation 像下一个代码但没有成功 :
<div *ngFor="let product of products | mypipe : {{product.productColor}}">
<label>{{product.productName}}</label>
</div>
【问题讨论】:
-
你想做什么?
-
我希望
mypipe按任何产品属性过滤我的产品,在本例中为productColor。mypipe还会收到第二个参数以进行过滤,在这种情况下为颜色(例如蓝色) -
let product of products | mypipe : product.productColor应该如何工作?当products通过管道传送到mypipe时product不存在,因为应该应用mypipe以使product存在。这是先有鸡还是先有蛋的困境,也是 XY 问题。请提供所有相关的源代码并修改问题,以便它反映真正的问题,而不是您期望的解决方式(无论如何它都不会起作用)。
标签: angular angular2-template angular2-directives angular2-pipe