0

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)

1 Answers1

0

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]
}
Mohammad Babaei
  • 473
  • 6
  • 16
  • 1
    Sorry for late response, and thank you. I ended up using my service.ts which is similar to your answer. I found it still the easiest way to control data after all. Hands down to my lazy brain module – Ivar_the_clueless Jan 03 '22 at 16:34