我需要手动(或自动)更改数组中对象的detect属性。我在ngFor循环中有productShops实体的数组,它由“isNotDeleted”属性过滤。当我更改isNotDeleted属性的值时,angular不会检测到更改。
<ul class="nav nav-tabs">
<li *ngFor="let productShop of product.productShops | filter:'isNotDeleted':true" >
<a href="#categoryAssocTab{{productShop.shop.id}}" data-toggle="tab">{{productShop.shop.name}}</a>
</li>
</ul>
编辑:管道实施:
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({
name: 'filter'
})
export class FilterPipe implements PipeTransform{
transform(value:Array<any>, property, equal){
let properties = property.split('.')
if(value){
return value.filter(item => {
let finalValue:any = item
properties.forEach(p => {
finalValue = finalValue[p]
})
return finalValue == equal
})
}
return []
}
}
答案 0 :(得分:1)
您的管道应该标记为不纯,因为即使输入没有改变,给定输入的转换结果也会改变。
@Pipe({
name: 'filter',
pure: false
})
另见