Hulk Bulk Hulk Bulk - 1 year ago 72
AngularJS Question

Passing params through ui-router to the server

I have some troubles with geting single user basing on his ID. I can remove this certain user with DELETE in my app but I can't get informations about him using "GET".

this is my angular app.js

app.controller('editUser', function($scope, $http, $state) {
$http.get('users/editUser/'+$state.params.userId).success(function(data) {

and this is my users.js routes file

router.get('/editUser/:userId', ensureAuthenticated, function(res, req, next) {
var userId= req.params.userId,

getUser.findOne({'_id': userId}, function(err, user) {
if(err) throw err;
data = user;

after clicking on "edit" button I am redirected to users/editUser/ffw23rfaw - its id, and basing on this id I use get function to get info about him but I get 500 "Internal server error". I would like to add that removing user is pretty much same and it works.

after clicking Edit button I do this

$scope.editUser = function($index) {
$state.go('editUser', {userId: $index});

that's how I get userId on 'users/editUser/' page

and this is my state config

.state('editUser', {
url: '/users/editUser/:userId',
templateUrl: '/views/editUser.html'

Answer Source

Found out the issue :) Your code has function(res, req, next) Change that to

function(req, res, next)

just wrong placement of parameters (variable names). Hope this helps. (thanks for pointing out the console message)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download