更新时间:2023-11-26 16:36:52
那是因为如果你使用 push
向数组添加新项,那么在执行纯管道时,数组引用不会改变仅当它检测到对输入值的纯粹更改(在您的情况下为 array
和 value
)
That's because if you use push
to add new item to array then the array reference isn't changed while pure pipe will be executed only when it detects a pure change to the input value (array
and value
in your case)
有两种解决方案:
1) 返回新数组
this.array = this.array.concat(4)
或
this.array = [...this.array, 4];
2) 使用不纯的管道
@Pipe({name: 'contains', pure: false})
export class ContainsPipe implements PipeTransform {
更多详情请见