AngularJS / PHP / Javascript - I can not update the value of ng-model

0

First good evening. I have a simple table that is fed by a 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 through an http.post request. The problem is that ng-models are not updating after burning, thus keeping the old values. Guys, I think it's some simple slide of mine with respect to passing parameters ... can you give me some 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();
            });
}

    
asked by anonymous 18.04.2018 / 04:43

1 answer

0

So I understand, you're using ng-repeat to generate your grid right? If this is indeed the case, make sure that in addition to updating your database you also update your responsible array of data. If the line responsible for updating the data is:

$scope.entradas = data;

Remember that the syntax for capturing the return body will be:

$scope.entradas = data.data;
    
23.04.2018 / 21:40