Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$stateParams not available in abstract state #1197

Closed
devaroop opened this issue Jul 10, 2014 · 3 comments
Closed

$stateParams not available in abstract state #1197

devaroop opened this issue Jul 10, 2014 · 3 comments

Comments

@devaroop
Copy link

I want to access the url parameter($stateParam) inside a abstract state while calling a child state. I am curious to know how that can be done. http://plnkr.co/edit/L0TXx3DCBOJmh4XydXbV?p=preview

$stateProvider
        .state('contacts', {
            abstract: true,

        //my whole point is to get the id=1 here :(

        url: '/contacts/:id',
        templateUrl: function($stateParams){
            console.log("Did i get the child's parameter here? " + $stateParams.id)
            return 'contacts' + $stateParams.id + '.html'; //this will have a ui-view in it which will render its detail.
        }
    })

    .state('contacts.detail', {
        url: '/:id',
        // loaded into ui-view of parent's template
        templateUrl: 'contacts.detail.html',
        controller: function($scope, $stateParams){
          $scope.person = $scope.contacts[$stateParams.id];
        },
        onEnter: function(){
          console.log("enter contacts.detail");
        }
        })
    })

in view:

<a ui-sref="contacts.detail({id: 1})">My first contact<a>

Any help is deeply appreciated.

@timkindberg
Copy link
Contributor

I don't think you'll be able to have two params named the same. You have :id in both the parent AND the child. Give them unique names.

@devaroop devaroop reopened this Jul 10, 2014
@devaroop
Copy link
Author

@timkindberg: That's wonderful and is working like a charm. Thanks for your quick reply and the perfect solution.

@Ema4rl
Copy link

Ema4rl commented Mar 23, 2015

Nice one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants