javascript - AngularJs, how send params for $http get -
this question has answer here:
- angularjs passing data $http.get request 7 answers
i'm trying pass value of identifier through url express router, variable want pass idr got correctly $routeparams.idr , have pass $http, can't it.
that 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 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 token filter , arriving @ method correctly:
router.get('/obtenerdestinosruta', function(req,res){ var query = "select * public.\"destino\" d " + " join public.\"rutadestino\" rd on d.\"idd\" = rd.\"idd\"" + " \"idr\" = " + req.body.idr+ " order 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 value had stored in requestdata (which 5), tried several ways without result, in console "req.body.idr" undefined, , if change "req.body.idr" in statement value 5, works perfectly, idea of how can done?
this it's query result console.log:
select * public."destino" d join public."rutadestino" rd on d."idd" = rd."idd" "idr" = undefined order d."idd" asc
regards.
can put route definition?
in route definition have specify expected parameters, in:
module.config(['$routeprovider', function($routeprovider) { $routeprovider. when('/routename/:idr', {templateurl: 'template.html', controller: myctrl}) }]);
note ":idr" value in route.
then in controller can access $routeparams.idr
Comments
Post a Comment