Create your own scope with each ng-repeat iteration

Asked

Viewed 37 times

1

I’m trying to make a table of values to be filled and stored, row by row. However, even after filling and storing the first line, by changing the value of a select, the select of all lines above the one I am entering are having their values changed.

It is possible to isolate each line with its own scope?

Code:

 <tr class="odd" ng-repeat="itemSaida in vm.itensSaida"> 
                                <!-- SELECT DE PRODUTOS -->
                                <td class="expand">
                                     <span class="responsiveExpander">
                                         <select class="form-control" ng-disabled="itemSaida.id && !itemSaida.editando" ng-model="itemSaida.fkProduto" ng-options="produto.id as (produto.id + '-' + produto.nome) for produto in vm.produtos" ng-change="post('carregar-estoque/'+ itemSaida.fkProduto, {indice: $index})">
                                             <option value="">-- SELECIONE --</option>
                                         </select>
                                     </span>
                                </td>

                                <!-- Unidade -->
                                <td class="expand">
                                     <span class="responsiveExpander">
                                         <input type="text" class="form-control text-left" ng-disabled="true" auto-focus ng-model="vm.unidade">
                                     </span>
                                </td>

                               <!-- SELECT DE ESTOQUES -->
                               <td class="expand">
                                   <span class="responsiveExpander">
                                        <select class="form-control" ng-disabled="itemSaida.id && !itemSaida.editando" ng-model="itemSaida.fkEstoque" ng-options="fkEstoque.id as (fkEstoque.tipoEstoque.nome + ': Qtde:' + fkEstoque.quantidade) for fkEstoque in vm.estoques" ng-change="get('carregar-data-vencimento/'+itemSaida.fkEstoque)">
                                            <option value="">-- SELECIONE --</option>
                                        </select>
                                   </span>
                               </td>

                               <!-- Vencimento -->
                               <td class="expand">
                                    <span class="responsiveExpander">
                                        <input ng-model="vm.vencimento" mask="date" type="text" class="form-control text-left" ng-disabled="true" auto-focus>
                                    </span>
                               </td>

                               <td class="expand">
                                    <span class="responsiveExpander">
                                        <input type="text" class="form-control text-left" ng-disabled="itemSaida.id && !itemSaida.editando" ng-model="itemSaida.quantidade" id="quantidade" mask="decimal" maxlength="15" placeholder="Quantidade">
                                    </span>
                               </td>

To make it a little easier to understand: this is a list of items in which each row of a table will be responsible for registering an item. The figure below illustrates: inserir a descrição da imagem aqui

After saving the first item, when I will select the product in the bottom row, it is updating the unit both in the top row and the bottom one, but the top one should stay with the old value. This is happening because of the angle. A get request is made on the server, which updates the vm.unit variable, which ends up updating both lines..

  • I did not understand the question, how to post the code? or show a print

  • I tested this post and it doesn’t occur on my test. Maybe we need more code from you so we can figure out why this behavior.

  • Guys, thanks for the feedback. I posted an image about the problem and a better description. See if you can help me please.

No answers

Browser other questions tagged

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