Take bank dice and play in a select

Asked

Viewed 77 times

0

Here I take all the employees of the company (this is correct, I already do on another page of the application and pull the data straight by . getFunctionaries)

setConsultores(){
     this.userService.getFuncionarios()
     .subscribe(response => {
       this.funcionarios = JSON.parse(JSON.stringify(response))
       this.allFuncionarios = this.funcionarios
         for (let funcionario of this.allFuncionarios) {
           this.allFuncionarios.push(funcionario)
         }
     })
}

Already on the front, I put select this way

  <strong>Selecione um consultor para atender a empresa:</strong>
      <select class="form-control" name="consultorSelected" id="consultorSelected" (ngModelChange)="setConsultores()">
        <option *ngFor="let funcionario of allFuncionarios" value="{{funcionario.id}}">{{funcionario.nome}}</option>
      </select>

However, you are not pulling these values, in case I just want the name of the employee to appear and the value is the ID of the selected employee.

  • But there is some error in the console?

  • none, I tried to put the call of the function setConsultores() in ngOnInit, then it ends up loading the page a lot and hangs.

1 answer

0


Your HTML has some things wrong with it. Try it this way:

<select [(ngModel)]="funcionarioSelecionado">
    <option selected disabled>Selecione</option>
    <option *ngFor="let funcionario of funcionarios">
        {{funcionario.nome}}, {{funcionario.sobrenome}}
    </option>
</select>

And the ts:

funcionarioSelecionado: string;
funcionarios: any = [];

// Seu construtor

ngOnInit() {
    this.usuarioService.buscarTodos().subscribe(data => this.funcionarios = data);
}

Browser other questions tagged

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