Select option select and send data in input according to the selected option so that it enters a different function

1

I have a% co_of% of 27 options and a% co_of%:

Depending on the selected option of select I have to send a different data in input as well as have to enter a function.

<div class="select" *ngIf="bandcatalogonis" >
<select name="seleccion" id="op" (change)="Opciones($event.target.value)">
<option value="1" id="opts">ID</option>
<option value="2" id="opts">Nis</option>
</select>
<input type="submit" value="Buscar" id="buc" (click)="buscar()">

Create a function where valid which option was selected:

 Opciones(opc) {
    //console.log(opc);
    if(opc == '1'){
      console.log("ID 1");
    }else if(opc == '2'){
      console.log("ID 2");
    }else if(opc == '3'){
      console.log("Perimetro");
    }else if(opc  == '4'){
      console.log("X");
    }

The problem is that when you sent the data only enters a function, I could not make it through the selected option sent a different data and enter different functions:

buscar() {
    if (this.dos === null) {
      this.bandnisnull = true;
      setTimeout(() => {
        this.bandnisnull = false;
      }, 2100);
    } else {      
      this.buscarClaveCat();
      this.bandtabla1 = false;
      this.bandtablaclavecat2 = true;
    }
}

Any suggestions please.

    
asked by Luis Medina 13.08.2018 в 19:14
source

1 answer

-1

By using the [(ngModel)] directive you can get the option selected in select , Try this:

Declare a variable in your component:

yourComponent.ts

seleccion:any;

yourComponent.html

<select name="select" [(ngModel)]="seleccion" name="op">
    <option value="1" selected>opcion 1</option>
    <option value="2">opcion 2</option>
  </select>

    <input type="text" [placeholder]="seleccion">

As you can see, you can get the value that has been selected in the select, and use it according to your needs. I hope I have approached the solution of the problem.

    
answered by 13.08.2018 в 20:07