I expose the code to see if someone can help me
HTML code with the button that calls the function:
<div id="btn_crearcurs" class="btn_curs">
<a class="btn btn-warning btn-lg btn-block" ng-click="crearCursos()">Crear cursos i aules</a>
</div>
AngularJS driver that passes the data to NodeJS:
$scope.crearCursos = function () {
$scope.loader.loading = true;
var lista = $scope.selected;
if (lista.length <1)
{
alert("No ha seleccionat ningún curs.");
}
else
{
$scope.loader.loading = true;
$http.post("/cursos/cursosC", {
'seleccio' : $scope.selected,
'ip' : $rootScope.mi_ip,
'usu' : $rootScope.idUsu,
'cif' : $rootScope.cifAssoc
})
.success(function (data, status, headers, config) {
$scope.loader.loading = false;
$state.go("private.adminsAssoccurs");
})
.error(function (error) {
$scope.loader.loading = false;
console.log(error);
});
$state.go("private.adminsAssoccurs");
}
};
Code (path) in NodeJS that inserts the records in the MySQL database:
app.post('/cursos/cursosC', function (req, res) {
var seleccio = req.body.seleccio;
var ip = req.body.ip;
var usuari = req.body.usu;
var cif = req.body.cif;
var valores = preparaMatriz(seleccio, ip, usuari, cif);
db.get().query("INSERT INTO cursoscentres (cifAssocCursAssoc, cursAssoc, descripcioCursAssoc, aulaCursAssoc, datacreacioCursAssoc, ipcreacioCursAssoc, usuaricreacioCursAssoc, altaCursAssoc) VALUES ?", [valores], function (err, result) {
if (err) {
var data = {"error": 1, "err": err};
return data;
} else {
var data = {"error": 0};
//console.log(data);
return data;
}
});
});