How to delete data using angular, php and ui-route?

1

I'm trying to make a method to delete a record from the database and the following message looks like in the console:

  

GET

>

I'm using ui-router's angular.

Here are my codes:

html:

<table width="200">
    <tr>
        <td><b>País</b></td>
        <td><b>Sala</b></td>
    </tr>
    <tr ng-repeat="pais in paises">
        <td>{{pais.nome}}</td>
        <td>{{pais.sala}}</td>
        <td><a ui-sref="editarPais({idPais: pais.idPais})">[ ]</a></td>
        <td><a ng-click="apagarPais(pais.idPais)">[x]</a></td>
    </tr>
</table>

Angular:

app.controller("PaisesController", function ($scope, $http, $stateParams, $state) {

$scope.apagarPais = function (pais) {
    console.log("id "+pais);
    $http.get("admin/php/apagaPais.php?idPais="+pais)
    .success(function (data, status){
        console.log(data);
        carregaPaises();
    });
};

carregaPaises();

});

php:

include_once("conexao.php");
$pdo = conectar();

$id = $_POST['idPais'];
print_r($id);

$apagaPais=$pdo->prepare("DELETE FROM paises WHERE idPais=:id");
$apagaPais->bindValue(":id", $id);
$apagaPais->execute();
    
asked by anonymous 12.01.2016 / 18:46

1 answer

2

You need to inform PHP which ID should be removed, so you need to SEND the angle ID to PHP.

Use $http.post instead of $http.get .

Otherwise, the .then() method will only work if you have a promise being returned, which is not the case with the .get method. The error may be so, but still, the deletion will not work.

    
12.01.2016 / 19:06