Problems with select component

Asked

Viewed 110 times

4

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

In this my HTML I use ng-repeat to list all items, and when my screen is loaded my first and only item is: {{list name.}}, when I click on this item {{list name.}, ai loads the list of 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 anyone can give you a hint, I’d appreciate it!

  • the user object has user credentials?

  • Yes, the object has the credentials of the user who is logged in, that object I pass to the send (PUT) and receive the list of affiliates of that user.

  • Be careful, because storing it in the client is not safe

  • And what is the best practice for it?

  • Server-side cookies, validation with Oauth2 (confusing, more secure medium), Digest, etc... Give a search in these paradigms : )

  • Okay, I’ll look into it! As for the current problem, do you have any tips? Thank you

  • have tried to fill this select otherwise, such as ngOptions?

Show 2 more comments

1 answer

0


I was able to solve using ng-if, where it removes the element and creates 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 don’t know if this is the best way, but it solved the problem.

Browser other questions tagged

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