I'm trying to pass the value of an identifier through a url to an express router, the variable I want to pass is IDR that I got it correctly from $routeParams.IDR and now I have to pass it by $http, but I can't do it.
That is my controller.js ( $routeParams.IDR work good)
app.controller("rutaDestinosCtrl", function($scope, $http, userService, $routeParams){
vm = this;
vm.destinos = [];
var requestData = {
'IDR': $routeParams.IDR //$routeParams.IDR is for example: 5
};
vm.funciones = {
obtenerDestinos : function(){
$http({
method: "GET",
url: '/privadas/rutas/obtenerDestinosRuta',
requestData,
headers: {'auth-token': userService.token}
})
.then(function(respuesta){
vm.destinos = respuesta.data.data;
}, function(respuesta){
console.log("Error:", respuesta.status);
})
} //obtenerDestinos
}//funciones
vm.funciones.obtenerDestinos();
});
After passing the token filter and arriving at this method correctly:
router.get('/obtenerDestinosRuta', function(req,res){
var query = "SELECT * FROM public.\"Destino\" D " +
" JOIN public.\"RutaDestino\" RD ON D.\"IDD\" = RD.\"IDD\"" +
" WHERE \"IDR\" = " + req.body.IDR+ " ORDER BY D.\"IDD\" ASC";
console.log(query);
db.query(query).spread(function(result, metadata){
res.json({
data: result
})
}).catch(function(err){
res.status(500).send("Error: "+ err);
})
});
I can't get the value I had stored in RequestData (which would be 5), I tried it several ways without result, in console "req.body.IDR" is undefined, and if I change "req.body.IDR" in the statement by the value 5, works perfectly, any idea of how it can be done?
This it's the query result from the console.log:
SELECT * FROM public."Destino" D JOIN public."RutaDestino" RD ON D."IDD" = RD."IDD" WHERE "IDR" = undefined ORDER BY D."IDD" ASC
Regards.