How to pick up combobox value at Angular 1.x

Asked

Viewed 296 times

0

I have a combobox in my view and want to take the value of it and print on the screen somewhere else, I am managing to print only the index of the selected item, will someone help me?

HTML:

                                       <div  class="form-group">
                                            <label>Departamento</label>
                                            <span style="color: red;">*</span>
                                            <select ng-model="orientador.value"
                                                    class="form-control"
                                                    ng-required="true">
                                                <option value="">Selecione o departamento:</option>
                                                <option ng-repeat="option in lista_departamento.availableOptions" value="{{option.id}}">{{option.name}}</option>
                                            </select>
                                        </div>
                                       {{orientador.value}}

JS:

 $scope.lista_departamento = {
        availableOptions: [],
        model: null
    };

  //---------------------------------------get Lista Departamneto

    var getListaDepartamento = function () {
        $http.get("get_departamento").then(function (resposta) {
            var departamento = [];
            for (var i in resposta.data){
                departamento.push({id: resposta.data[i].cod_departamento, name: resposta.data[i].nome});
            }
            $scope.lista_departamento.availableOptions = departamento;
        });
    };

    getListaDepartamento();

RESULT: inserir a descrição da imagem aqui

1 answer

1

I was defining value as my id, reused a code of mine that needed it and I forgot to change it:

as was:

   <option ng-repeat="option in lista_departamento.availableOptions" value="{{option.id}}">{{option.name}}</option>

how it was meant to be:

   <option ng-repeat="option in lista_departamento.availableOptions" value="{{option.name}}">{{option.name}}</option>

Browser other questions tagged

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