How to get combobox value in Angular 1.x

0

I have a combobox in my view and I want to get the value of it and print it on the screen somewhere else, I'm just able to print the index of the selected item, can anyone 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:

    
asked by anonymous 08.03.2018 / 16:41

1 answer

0

I was setting value as my id, reused my code that needed it, and I forgot to change it:

how were you:

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

what it was meant to be:

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