How to send a multi-column harness on a single button with ng-repeat and angular

Asked

Viewed 71 times

0

I have a form in the format of grid, in it I present the table information Itens from my bank (74 in total). The intention of this form grid is to add two fields: price and bdi price in all these items.

My problem is that I am not able to send the information of the 74 records in a single button.

I’m using the ng-repeat in the table to display the 74 items in my form grid, and still in this ng-repeat have the inputs.

HTML:

<div class="table-responsive">
<table class="table table-bordered table-hover table-condensed">
    <thead>
        <tr id="fundocoreditarcd">
            <th>Código Tipo Item</th>
            <th>Código Item</th>
            <th>Descrição</th>
            <th>Preço</th>
            <th>Preço BDI</th>
            <th>Ações</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="item in itens">
            <td>{{item.tipo_item_cod_tipo_item}}</td>
            <td>{{item.cod_item}}</td>
            <td>{{item.descricao}}</td>
            <td><input type="text" ng-model="item.preco" class="money" id="preco" /></td>
            <td><input type="text" ng-model="item.precoBdi" class="money" id="bdi" /></td>
            <td><a href="/cid/editarLote"><span class="glyphicon glyphicon-pencil"></span></a> <a href="http://geradormemes.com/media/created/8kbx7r.jpg" class=""><span class="glyphicon glyphicon-trash"></span></a> </td>

        </tr>
    </tbody>

    <button ng-click="addPrecoItens(item)" class="btn btn-primary">Enviar</button>
</table>

Part of the controller JS:

$http.get("read/itens")
.success(function (item) {
    $scope.itens = item;
    console.log($scope.itens);
})
.error(function (erro) {
    console.log(erro);
});

$scope.addPrecoItens = function (item) {
$scope.itensLote = item;
console.log($scope.itensLote);
/*$http.put('read/itens/', $scope.itensLote)
    .success(function () {
        console.log($scope.itensLote);
        $scope.mensagem = 'itens editados!';
    })
    .error(function (erro) {
        $scope.mensagem = 'Erro ao editar itens!';
        console.log(erro)
    });*/
};
  • Can you explain better what you want to do? You want to send all 74 records to the backend by clicking the button?

  • I will receive a json document of arrays with 74 items, and using ng-repeat to display the information in the table. I want to send those 74 items with two more campus inputs by clicking the send to server button. I’m not getting the values of the table fields to send. In case I don’t know how to take the values displayed by ng-repeat to and send them.

  • I suppose your $scope.item have 74 items... then use the $index, ng-model="item[$index].precoBdi" for example, so Voce sends the updated model($scope.item) to the server

  • Yes, the 74 items are inside the $scope.item, however when we send the information by button function <input type="button" class="btn btn-primary" ng-click="addPrecoItens(item)" value="enviar"> O $scope.item is empty because it is outside the table of ng-repeat , when it is within the table of ng-repeat the$scope.item is filled in with the values of 74 itens, but the buttons repeat for each line of 74 itens Obs.: It didn’t work using the index the way you spoke, when clicking the return button on the empty screen.

No answers

Browser other questions tagged

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