0
First good night. I have a simple table that is powered by an SQL database. I developed a button that aims to update the contents of the "ng-model" according to what you type in a simple form. The table is updated via an http.post request. The problem is that the "ng-model" is not updating after the recording, thus keeping the old values. Guys, I believe it’s some simple slip of mine regarding the passing of parameters.... can give me a strength?
<!-- BUTTON EDITAR -->
<button ng-class="['uk-button', 'uk-button-primary', 'uk-button-small']" href="#modal-editar{{x.id}}" ng-click="updateRegister(x.id,x.cliente,x.descricao,x.valor,x.dataM,x.tipo)" uk-toggle>Update</button>
<!-- INICIO MODAL EDITAR -->
<div id="modal-editar{{x.id}}" uk-modal>
<!-- BOTÃO DE FECHAR -->
<div ng-class="['uk-modal-dialog']">
<button ng-class="['uk-modal-close-default']" type="button" uk-close></button>
<div ng-class="['uk-modal-header']">
<!-- TITULO DA ENTRADA -->
<h2 ng-class="['uk-modal-title']">{{x.titulo}}</h2>
</div>
<div ng-class="['uk-modal-body']">
<label ng-class="['formulario']">Cliente</label>
<input type="text" ng-model="ngCliente" ng-class="['uk-input','uk-form-width-medium','uk-form-small']"></input>
</div>
<div ng-class="['uk-modal-body']">
<label ng-class="['formulario']">Descricao</label>
<input type="text" ng-model="ngDescricao" ng-class="['uk-input','uk-form-width-medium','uk-form-small']"></input>
</div>
<div ng-class="['uk-modal-body']">
<label ng-class="['formulario']">Valor</label>
<input type="text" ng-model="ngValor" ng-class="['uk-input','uk-form-width-medium','uk-form-small']"></input>
</div>
<div ng-class="['uk-modal-body']">
<label ng-class="['formulario']">Data</label>
<input type="text" ng-model="ngDataM" ng-class="['uk-input','uk-form-width-medium','uk-form-small']"></input>
</div>
<div ng-class="['uk-modal-body']">
<label ng-class="['formulario']">Tipo</label>
<input type="text" ng-model="ngTipo" ng-class="['uk-input','uk-form-width-medium','uk-form-small']"></input>
</div>
<div ng-class="['uk-modal-footer uk-text-right']">
<button ng-class="['uk-button uk-button-primary uk-modal-close']" ng-click="updateRegisterIntoDB(x.id)" type="button">Salvar</button>
<button ng-class="['uk-button uk-button-secondary uk-modal-close']" type="button">Cancelar</button>
</div>
PHP
include("../sqlConnection/connection.php");
$data = json_decode(file_get_contents("php://input"));
if(count($data)>0)
{
$id = mysqli_real_escape_string($conexao, $data->value);
$cliente = mysqli_real_escape_string($conexao, $data->cliente);
$descricao = mysqli_real_escape_string($conexao, $data->descricao);
$valor = mysqli_real_escape_string($conexao, $data->valor);
$dataM = substr("$data->dataM",0,10);
$tipo = mysqli_real_escape_string($conexao, $data->tipo);
$query = "UPDATE listafinanceira SET cliente='$cliente',descricao='$descricao',valor='$valor',dataM='$dataM',tipo='$tipo' WHERE id = '$id'";
}
JAVASCRIPT
$scope.updateRegister = function(cliente,descricao,valor,dataM,tipo)
{
$scope.ngCliente = cliente;
$scope.ngDescricao = descricao;
$scope.ngValor = valor;
$scope.ngDataM = dataM;
$scope.ngTipo = tipo;
}
//objeto responsável por atualizar o formulario com os dados preenchidos dentro do modal
$scope.updateRegisterIntoDB = function(value)
{
$http.post(
"../sqlFunctions/updateForm.php",
{value:value,cliente:$scope.ngCliente,descricao:$scope.ngDescricao,valor:$scope.ngValor,dataM:$scope.ngDataM,tipo:$scope.ngTipo}
).then(function(data){
alert("Cadastro atualizado com sucesso");
$scope.entradas = data;
$scope.displayData();
});
}
I already solved young, it was simple thing. But I appreciate your answer!
– Codeman