Keep an angle combobox selected

Asked

Viewed 595 times

0

I am using Angularjs to fill out the data of a form within a modal. have a function editarSolicitacao(solicitacao) which runs from the button click event. When the modal opens the field is selected but the selection quickly disappears and I noticed that the following tag is created in HTML

<option value="? number:7 ?"></option>


 <select ng-model="solicitacao.setor_id" class="form-control" required>
                        <option value="">(Selecione)</option>
                        <option ng-value="setor.id" ng-repeat="setor in setores" ng-bind="setor.id" ng-selected="setor.id == solicitacao.setor_id"></option>
                        </select>

Someone’s been through something like this and can tell me how to proceed?

my function which opens the modal and fills the form:

$scope.editarSolicitacao = function(solicitacao)
    {
        unidadeMedidas();
        setores();

        $scope.solicitacao = solicitacao;
        $scope.produtos = $scope.solicitacao.produtos_adicionados;
        $scope.showProdutos = true;

        modal();
    }



 unidadeMedidas = function()
    {
         $http({
            method: 'GET',
            url: '/unidade-medida/consultar'
        }).then(function(response){
            $scope.unidades = response.data;

        },function(responseError){
            wgmAlert(responseError.statusText);
        });
    }



    setores = function()
    {
        $http({
            method: 'GET',
            url: '/setores'
        }).then(function(response){
            $scope.setores = response.data;

        },function(responseError){
            wgmAlert(responseError.statusText);
        });
    }



    modal = function()
    {
        $scope.modal = Modal({
            animation: 'slideDown',
            draggable: true,
            width: $(window).outerWidth() -300,
            title: 'Solicitação',
            height: $(window).outerHeight() - 100,
            template: $('#template-form-solicitacao').html(),
            clickOut: false
        },$scope);
        $scope.modal.show();
    }

1 answer

1

How you created your ?

Are you setting ng-model? How options are being generated?

An example:

<select ng-model="suamodel" name="selectUm">
<options ng-repeat="optionsValue as modelComOptions" value={{optionsValue.id}}>{{ optionsValue.descricao }}</options>
</select>

Documentación Angular

  • I edited the question. When I open the modal for the first time it is selected. If I close and open again it does not keep selected.

  • I managed to solve the problem.

  • @Miguelbatista I am with this same problem can inform me how it solved?

Browser other questions tagged

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