【发布时间】:2017-10-07 23:29:07
【问题描述】:
我有一个简单的管道:
export class MergePipe implements PipeTransform {
transform(first: any[], second: any[], order: Boolean): any {
return order ? first.concat(second):second.concat(first);
}
我在一个简单的按钮上使用它:<button *ngFor="let item of items | sort:suffix | filter:filterargs | merge:newItems:false"></button>。
然后使用 newItems.push(values) 将一些值推送到 newItems 中,但没有任何反应。如果我从 *ngFor 中删除管道,我会收到预期的更改。
我想我对数据绑定的工作方式有误解。
感谢您提供任何有用的信息。
【问题讨论】:
-
纯管道仅在更改
pointer时更新,例如您的first更改为另一个数组,而不是可变的本身。您可以通过设置@Pipp({ pure: false })更改为不纯管道。你可以搜索管道文档。 -
感谢您的回答。使用不纯的管道它可以正常工作,但现在并不真正了解它是如何工作的。
标签: angular data-binding pipe concat