0

I have the folowing link in asp.net mvc:

@Html.ActionLink(user.Alias.ToUpper(), "Employee", new { controller = "User", id = user.Alias, area = "Organization" }

(.../Organization/Employee/someId#/)

how can I get id value in angularjs controller?

.controller('UserCtrl', function ($scope, $location, User) {

    $scope.user = User.get({ id: ??? })
})

thanks in advance for any help!

1
  • are you using ng-route or ui-router Commented Oct 9, 2014 at 11:03

3 Answers 3

2

If you are using ng-route, use $routeParams.someId.

.controller('UserCtrl', function ($scope, $location, $routeParams, User) {
    $scope.user = User.get({ id: $routeParams.someId });
})

If you are using ui-route, use $stateParams.someId.

.controller('UserCtrl', function ($scope, $location, $stateParams, User) {
    $scope.user = User.get({ id: $stateParams.someId });
})
Sign up to request clarification or add additional context in comments.

1 Comment

nope. Still not working. Maybe problem is in the way I'm passing parameters?
2

You should use $routeParams See this example: https://thinkster.io/egghead/routeparams-api/

Comments

0
.controller('UserCtrl', function ($scope, $location, $stateParams, User) {

     $scope.someid = $stateParams.someId

})

2 Comments

neither $stateParams and $routeParams cannot get the value
someId is an actual value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.