angular为了提高应用的性能,把管道分为纯管道和非纯管道,纯管道只会在检测变更以后更新数据,对于一些引用类型对象使用纯管道,当引用对象内部发生变化的时候,不会触发检测变更,纯管道也就不会更新数据。管道默认是纯管道,纯管道也会让应用性能更高。如果我们自己创建的管道需要使用非纯管道只需要在管道的@Pipe装饰器中设置pure属性为false即可:
@Pipe({
name: 'flyingHeros',
pure: false
})
export class FlyingHerosPipe implements PipeTransform {
transform(allHero: Hero[]): unknown {
return allHero.filter(hero => hero.canFly);
}
}