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

Inconsistent API in state params that are functions #1641

Closed
kvcrawford opened this issue Dec 17, 2014 · 1 comment
Closed

Inconsistent API in state params that are functions #1641

kvcrawford opened this issue Dec 17, 2014 · 1 comment

Comments

@kvcrawford
Copy link

@kvcrawford kvcrawford commented Dec 17, 2014

When a state has a default parameter that is a function, the function is invoked, and the param is set to the return value of that function.

However, if you pass a function as a param like so

$state.go('foobar', {
  myParam: function () { console.log('hello'); }
});

That function does not get invoked and its return assigned as the param value. Rather, it is available as a function on the $stateParams object. This is a powerful way to provide a state with a callback (see #1640) when navigating to it from a certain context.

Both use-cases are valuable, but API consistency is desirable, and I wanted to confirm that it's not a bug. Perhaps an option could be added to the param config object?

Another possibility is to require an IIFE if you want a function that returns a value for setting on the param:

$stateProvider.state('foobar', {
  params: {
    myParam: (function(){ return 'foo'; })()
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.