How can I get these values from the ion select?


#1

How do I get the values of the client firstname and surname when the user selects the client id in the ion select? I get the clientId but I want the names themselves.

          <ion-item>
            <ion-label stacked>Client</ion-label>
            <ion-select formControlName="clientId">
                <ion-option *ngFor="let client of clientList | async" [value]="client.clientId">{{client.firstName}} {{client.surName}}</ion-option>
              </ion-select>
          </ion-item>

#2

wouldn’t you bind on client, instead of client.clientId

[value]="client"

then u would have access to all the client attributes


#3

I can get all the client attributes inside the ion option but anywhere else. I need to pass the clientID, firstname and surname to a set method in a provider.


#4

sorry, i don’t understand your reply.

u asked how to get the values when the option is selected.

so, you would pass back the client structure (instead of just one field), and in the code behind extract the important fields.


#5

I want the user to select a client from the list and then to capture the clientID, clientFirstName and clientSurname in order to save it in my firestore database.

export class CreateSessionPage {

  public createSessionForm: FormGroup;
  
  public clientList: Observable<client[]>;

  constructor(public navCtrl: NavController, public loadingCtrl: LoadingController,
    public alertCtrl: AlertController, public clientPro: ClientsProvider, public sessionPro: SessionsProvider,
    formBuilder: FormBuilder) {

      this.createSessionForm = formBuilder.group({
        sessionDate: ['', Validators.required],
        sessionTime: ['', Validators.required],
        clientId: ['', Validators.required]
      });

  }

  ionViewDidLoad() {
    this.clientList = this.clientPro.getClientList().valueChanges();
  }

  createSession(): void {
    const loading: Loading = this.loadingCtrl.create();
    loading.present();
  
    const sessionDate = this.createSessionForm.value.sessionDate;
    const sessionTime = this.createSessionForm.value.sessionTime;
    const clientId = this.createSessionForm.value.clientId;


#6

right, so

this.createSessionForm.value

would be ‘client’

[value]="client"