0

so, in my app.js :

.state('app.packages', {
  url: "/packages/:packagesId",
  views: {
    'menuContent' :{
      templateUrl: "templates/packages.html",
      controller: function ($stateParams) {
        console.log($stateParams);
      }
    }
   }
})

in browser console, it showing this :

Object {packagesId: "25242039"}

How do i access the $stateParams that hold the value of packagesId inside controller.js?

Currently doing it like this, but it is not working...

.controller('PlaylistCtrl', function($scope,$stateParams) {
  $scope.getId = function(){
    return $scope = $stateParams.packagesId ;
 };
})
1
  • 1
    Have you referenced the right controller in your state ? (the snippet you show us still has controller: function ($stateParams) {console.log($stateParams);} Commented Jul 23, 2014 at 15:48

1 Answer 1

1

First off, I don't understand why you want to assign the id to the scope return $scope = $stateParams.packagesId;

Secondly, you have a controller PlaylistCtrl, so you need to set it for router state.

 // you may try simple view first
.state('app.packages', {
  url: "/packages/:packagesId",
  templateUrl: "templates/packages.html",
  controller: 'PlaylistCtrl'
Sign up to request clarification or add additional context in comments.

1 Comment

owh..thanx a lot ! i just dont realize that i assign it to wrong controller. It should be PlaylistCtrl and not PlaylistsCtrl

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.