<ion-select> Binding

I got a “Kompetenzbereich” in my “note”-Object and i want the ion-select to automatically select the right “Kompetenzbereich”.

  <ion-item>
    <ion-label position="stacked">Kompetenzbereich</ion-label>
    <ion-select 
      multiple="false" 
      cancelText="Cancel" 
      okText="Ok"
      [(ngModel)]="note.lntKompId"
    >
      <ion-select-option *ngFor="let komp of kompetenzbereiche" [value]="komp">
        {{ komp.komBezeichnung }}
      </ion-select-option>
    </ion-select>
  </ion-item>

Can you show us the part where you assign to note.lntKompId?

1 Like
  ngDoCheck() {
    this.note = this.exchange.note;
  }

The problem just appears with the <ion-select>, with for example for a string or a date, it works fine.

  <ion-item>
    <ion-label 
    position="stacked">Testdatum</ion-label>
    <ion-datetime 
      displayFormat="DD/MM/YYYY" 
      min="2015-09-01"
      [(ngModel)]="note.lntTimestamp"
      >
    </ion-datetime>
  </ion-item>

I asked for where you assign to note.lntKompId, not note. As you seem to be on the road to discovering out, the problem likely lies with JavaScript’s crappy fake OO “support” and the difficulty of comparing objects for equality. I can’t say much further without seeing a MCVE.

1 Like

this is a property of note i get from the backend. i don’t assign it explicit.

i implemented a compareWith for my ion-select, now if i click on the select, the value is selected, but not displayed from the beginning

Finally after a long time searching i found a solution on this post:

The selectedText Attribute in combination with a compareWith Function did solve the problem.