Problems with select component

4

I have a problem submitting my list of items from my select.

In my HTML I use ng-repeat to list all items, and when my screen loads my first and only item is: {{list.name}} , when I click on that item {{list.name} , then load the list correctly.

<select data-placeholder="Escolha uma Empresa/Filial" multiple chosen
                                style="width: 100%;"
                                ng-model="filtroRequisicao.codigoSistemaUsuariosFiliais"
                                required>
                            <option ng-repeat="list in lista" ng-value="list.id">
                                {{list.name}}
                            </option>
                        </select>

Angularjs:

$scope.lista = [{}];

    //Carrega as Filiais dos Cooperados
        $scope.loadFiliais = function () {
            var usuario = localStorage.getItem("usuarioAutenticado");
            var objetoUsuario = {};

            objetoUsuario = JSON.parse(usuario);


            $http({
                method: 'PUT',
                url: '/getFiliais',
                data: objetoUsuario
            }).then(function (response) {

                    $scope.lista = response.data;

                    console.log($scope.lista);
                },

                function (response) {
                    console.log(response.data);
                    $scope.showNoty('Nenhum dado encontrado.', 'information');
                });
        };

        $scope.loadFiliais();

If someone can give you some tips, thank you!

    
asked by anonymous 13.06.2017 / 21:28

1 answer

0

I was able to solve using ng-if, where it removes the element and creates it again according to the expression:

ngIf

angular:

Starts the variable: $scope.lista = [] ;

calls the function $scope.listaFiliais();

html:

<select data-placeholder="Escolha uma Empresa/Filial" multiple chosen
                                style="width: 100%;"
                                ng-if="lista.length > 0"
                                ng-model="filtroRequisicao.codigoSistemaUsuariosFiliais"
                                required>
                            <option ng-repeat="list in lista" ng-value="list.id">
                                {{list.name}}
                            </option>
                        </select>

I do not know if this is the best way, but solved the problem.

    
05.07.2017 / 15:07