I'm using pipe transform on <ion-select-option *ngFor="let item of collection | myPipe:someValueToFilter" [value]="item">
and the pipe will do some filter, map and sort.
How can I set default value to selectedItem
within <ion-select [(ngModel)]="selectedItem">
in transformed collection after pipe transforming? (Let's say the first item in transformed collection)
CodePudding user response:
I think you can use your pipe in component.ts
file instead of the template like this:
@Component({
...
providers: [MyPipe]
})
...
contractor(private myPipe: MyPipe)
then in your method or ngOnInit
hook use your pipe to filter your data and use its value where you want, for example, set to the selected item.
handleMyData(data): any {
this.collection = this.myPipe.transform(data, filters)
this.selectedItem = this.collection[0]
}