我有一個簡單管:角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