The itemCode, itemDescription, itemPreco, and itemQuantity fields are populated dynamically (at run time, without refresh ) from a query performed in the database. However, these values, when passed as a parameter to the addItem () function, return undefined
, that is, when clicking the "Insert" button, the fields that should be "cloned" to the table [Code | Description | Contact Us | Quantity] are left blank.
Illustration:
HTML:
<divng-app="app" ng-controller="controlador">
<input type="text" name="busca" placeholder="Pesquisar produto"/>
<br /><br />
<input type="button" value="Inserir" id="inserir-item" ng-click="addItem(itemCodigo, itemDescricao, itemPreco, itemQuantidade)"/>
<br /><br />
<input type="text" id="codigo" readonly ng-model="itemCodigo">
<input type="text" id="descricao" readonly ng-model="itemDescricao">
<input type="text" id="preco" readonly ng-model="itemDescricao">
<br /><br />
<td>{{item.codigo}}</td>
<td>{{item.descricao}}</td>
<td>{{item.preco}}</td>
<td>{{item.quantidade}}</td>
</div>
JavaScript:
var app = angular.module('app', []);
app.controller("controlador", function($scope){
$scope.addItem = function (itemCodigo, itemDescricao, itemPreco, itemQuantidade) {
$scope.items.push({
codigo: itemCodigo,
descricao: itemDescricao,
preco: itemPreco,
quantidade, itemQuantidade
});
};
})
Note: itemQuantity is defined in another input within the code.