我正在使用管道轉換,<ion-select-option *ngFor="let item of collection | myPipe:someValueToFilter" [value]="item">管道將執行一些過濾、映射和排序。
我怎樣才能默認值設定為selectedItem內<ion-select [(ngModel)]="selectedItem">的改造收集管轉換后?(假設轉換后的集合中的第一項)
uj5u.com熱心網友回復:
我認為您可以在component.ts檔案中使用管道而不是這樣的模板:
@Component({
...
providers: [MyPipe]
})
...
contractor(private myPipe: MyPipe)
然后在你的方法或ngOnInit鉤子中使用你的管道來過濾你的資料并在你想要的地方使用它的值,例如,設定為所選專案。
handleMyData(data): any {
this.collection = this.myPipe.transform(data, filters)
this.selectedItem = this.collection[0]
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/403264.html
標籤:
