Я использую этот фильтр:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'search'
})
export class SearchPipe implements PipeTransform {
transform(items: any[], field: string, value: string): any[] {
if (!items) {
return [];
}
if (!field || !value) {
return items;
}
return items.filter(singleItem =>
singleItem[field].toLowerCase().includes(value.toLowerCase())
)}
}
Введите:
<input placeholder="Nome do produto" [(ngModel)]="anunciosFiltro.name" type="text" name="filtra" id="filtra">
У меня есть таблица, к которой я применяю этот фильтр:
<div *ngFor="let tabelaAnuncioContas of sortedData?.Contas; let a = index" >
<table>
<tr *ngFor="let anuncio of tabelaAnuncioContas.Anuncio.products | search: 'name' : anunciosFiltro.name; let i = index">
<td>
<svg class="componenteTabelaResponsivo" matTooltip="Anúncio ativo" *ngIf="anuncio.status == 'enabled' && anuncio.associations[0].status == 'linked'" style="width:24px;height:24px" viewBox="0 0 24 24">
<path fill="rgb(161,196,66)" d="M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2Z" />
</svg>
</td>
</tr>
</table>
</div>
Мой фильтр каналов работает нормально, но когда я фильтрую и выполняю http-заявку, которая изменяет данные моей таблицы (sortedData)
, фильтр не обновляет данные:
changeDataTable(){
this.sortedData.Contas[this.indexContaAlterada].Anuncio.products[this.indexAnuncioAlterado].status = status;
}
Мой status
в шаблоне сохраняется в исходном значении.