@ygorfraga wrote:
I've got a problem. I have a list of cities, but when I use the search-bar, I just want the cities with the same name to appear.
Currently i'm trying this:
<ion-searchbar [(ngModel)]="selectedCity" [showCancelButton]="shouldShowCancel" (ionCancel)="onCancel($event)"> </ion-searchbar> <ion-item *ngFor="let city of cities | orderBy: name | filter: selectedCity"> <ion-label>{{city.name}}</ion-label> <button (click)="onActive(city.detalhe.id)" *ngIf="city.active" ion-button outline item-right>Desativar</button> <button (click)="onActive(city.detalhe.id)" *ngIf="!city.active" ion-button outline item-right>Ativar</button> </ion-item>But I know it will never works 'cause i'm sending the object city to the pipe 'filter' and not the name, how can I send just the name for the pipe? I need the object for the method 'onActive'
The Pipe:
@Pipe({ name: "filter", pure: false }) export class FilterArrayPipe implements PipeTransform { transform(items: Array<any>, conditions: {[field: string]: any}): Array<any> { return items.filter(item => { for (let field in conditions) { if (item[field] !== conditions[field]) { return false; } } return true; }); } }And 'selectedCity' is a String. When I try the pipe out with others strings, It works. Another point, I need to filter comparing the name of the object but I need the whole object after this.
Posts: 1
Participants: 1