Add value to an input as per selection of an angular/Ionic combobox

Asked

Viewed 225 times

0

I have an input text and need that when I choose an option in a combobox receive this value, but without deleting what is already written.

What I tried to:

 <ion-textarea name="resposta" #resposta value="{{insercaorapidasistema}}{{respostaautomatica.value}}"

My two attempts, one with ngmodel, the other with local variable.

<ion-item>
  <ion-label>Combo 1</ion-label>
  <ion-select #respostaautomatica>
    <ion-option value="opcao 1 ">Opcao 1</ion-option>
    <ion-option value="opcao 2 ">Opcao 2</ion-option>
  </ion-select>
</ion-item>

<ion-item>
  <ion-label>Combo 2</ion-label>
  <ion-select [(ngModel)]="insercaorapidasistema">
    <ion-option value="Opcao 1 ">opcao 1</ion-option>
    <ion-option value="Opcao 2 ">opcao 2</ion-option>
  </ion-select>
</ion-item>

The problem is that if I write something in the input text and then select a combobox value, what I write in the input goes away.

1 answer

0

I suggest you create another field to include the total value so that no circular reference occurs. For example:

<div>{{resposta.value}}{{insercaorapidasistema}}{{respostaautomatica.value}}</div>

<ion-textarea name="resposta" #resposta></ion-textarea>

<ion-item>
  <ion-label>Combo 1</ion-label>
  <ion-select #respostaautomatica>
    <ion-option value="opcao 1 ">Opcao 1</ion-option>
    <ion-option value="opcao 2 ">Opcao 2</ion-option>
  </ion-select>
</ion-item>

<ion-item>
  <ion-label>Combo 2</ion-label>
  <ion-select [(ngModel)]="insercaorapidasistema">
    <ion-option value="Opcao 1 ">opcao 1</ion-option>
    <ion-option value="Opcao 2 ">opcao 2</ion-option>
  </ion-select>
</ion-item>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.