Skip to content

passing params with ui-sref with a "urlless" state not passing params #708

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

Closed
samccone opened this issue Dec 20, 2013 · 4 comments
Closed

Comments

@samccone
Copy link
Contributor

Given markup

   a(ui-sref="foo({id: 123})") {{m.name.value}}

a state provider with

  $stateProvider.state('foo', {
    template: templates.foo,
    controller: 'foo'
  });

and a controller with

zap.controller('foo', function($scope, $state, $stateParams) {
  console.log($stateParams); // this is {}
});

State Params is an empty {} where I would expect id to be 123

@timkindberg
Copy link
Contributor

This isn't supposed to work. You need to declare state params for them to show up. If you don't use urls then you can declare params with the params property.

@samccone
Copy link
Contributor Author

hi @timkindberg thanks for the response. I searched the docs and wiki and did not find any docs on this topic. However I did locate where in the source code this is implemented. Would you mind showing me the de facto way to accomplish this? I will open a PR with a doc addition after.

Thanks

@samccone
Copy link
Contributor Author

Hi @timkindberg following your advice

I called

    $state.go('foo', {id: 123});

Since this calls
https://github.com/angular-ui/ui-router/blob/master/release/angular-ui-router.js#L1145

I would then expect from within my controller the ability to call $state.params or $stateParams and see a hash containing id:123

alas both are still {}

@samccone
Copy link
Contributor Author

ok so the solution as talked about here #175

in your state definition

  $stateProvider.state('foo', {
    template: templates.foo,
    controller: 'foo'
    params: ['id'] //array of param keys
  });
  $state.go('foo', {id: 123});

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

2 participants