我已經創建了一個管道,用於根據對象property.keep的值對對象數組進行排序。所有具有屬性show==0
和show==1
的對象都被刪除,沒有任何錯誤,並且可以在控制檯中看到。爲什麼管道不能正常工作?
pipe.ts
@Pipe({
name: 'menufilter'
})
@Injectable()
export class MyMenuFilterPipe implements PipeTransform {
transform(items: any[], args: any[]): any {
if (items) {
return items.filter(item => item.show == '0',console.log(item));
}
}
app.html
<tr *ngFor="let menu of specificmenus|menufilter" >
<td >{{menu.name}}</td>
</tr>
你確定'.show'屬性是一種字符串,而不是數字嗎? '0'和'0'之間有很大的區別 – CozyAzure
@CozyAzure它的32位intiger,即時消息在使用'0'和0時得到相同的結果0 – Ajith
你能在重新運行的程序中重現問題嗎?基於我所看到的(並且試過你的代碼)它應該工作得很好:) – Alex