我有一个简单管:角2:在管道中的concat阵列而不丢失数据绑定
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(值)将一些值推入newItems,但没有任何反应。如果我从* ngFor中删除管道,我会收到预期的更改。
我想我对数据绑定的工作方式有些误解。
感谢您提供任何有用的信息。
纯管道只在更改'指针'时更新,例如你的'第一个'换成另一个数组,而不能自己改变。你可以通过设置@Pipp({pure:false})来改变不纯的管道。您可以搜索管道文件。 –
感谢您的回答。用不纯的管子可以正常工作,但是现在还不能真正理解它是如何工作的。 – Draftsman