ng-model with undefined value in the controller

Asked

Viewed 137 times

1

I have a very strange problem. I have some filters that are like this.

<div ng-show="filtroReduzido" class="col-md-2">
   <div class="form-group">
        <label>Codigo Reduzido</label>
           <div class="form-group form-md-line-input no-hint right" style="padding-top: 3px;">
             <select id="servico"  
                     name="servico"  
                     chosen  
                     width="150"
                     allow-single-deselect="true"
                     ng-model="vm.filtro.des_servico"
                     style="width:100%"
                     ng-options="clienteFiltro as cliente.Des_Servico for cliente in vm.importacaoSiltDet |unique:'Des_Servico'| orderBy:'Des_Servico'"></select>
      </div>
    </div>
</div>

In the controller I declare the "filter"

 vm.filtro = {};

In my Function I call this ng-model but she comes undifined.
dateDe and dateAte are receiving the parameters normally, and the vm.relatorio is declared equal vm.filtro.

I don’t understand why the variables test2 and test3 are coming undifined, am I missing a step? maybe give a bind in the values of the filter parameters?

vm.filtrarDetFiltrado = function () {
            debugger;
            var dateDe = formatarData(vm.relatorio.dataDe);
            var dateAte = formatarData(vm.relatorio.dataAte);
            var test2 = vm.filtro.des_servico;
            var test3 = vm.filtro.Des_Servico;

inserir a descrição da imagem aqui

  • Initially try to declare a value for this variable, so: vm.filtro = { des_servico: null };

  • It declared thus getting des_servico:Undefined but in var teste3 it does not receive the filter parameter.

  • Take a look at the first example of Angular documentation.. Angularjs - Select, see if it helps you

  • I think I found the problem, I was in ng-options,I switched to ng-options="client.Des_servico for client in vm.importacaoSiltDet however now instead of passing the filter value this passing the grid object.

  • I just started this and it worked ng-options="client.Des_servico as client.Des_servico for client in vm.importacaoSiltDet

  • @Viniciuscano you can make an answer to your own post, to help future people with the same doubt

Show 1 more comment

1 answer

0

The problem was in the ng-options alias, I imagined it didn’t matter, but the old one was

ng-options="clienteFiltro as cliente.Des_Servico for cliente in vm.importacaoSiltDet

It should be getting lost in the clienteFilter, corrected using ng-options as follows.

ng-options="cliente.Des_Servico as cliente.Des_Servico for cliente in vm.importacaoSiltDet

Browser other questions tagged

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