Question

I have a URL parameter that I want to exist in all states. The parameter is 'asUser' and it allows admins to look at the app as another user. I tried:

$stateProvider
  .state("root", {
    params: ['asUser']
  })
  .state("root.login", {
    url: "/login",
    templateUrl: "/static/partials/login.html",        
    controller: 'LoginCtrl'
  })
  ...

But when I go to a url /login?asUser=123, I get this error in the console:

Failed to instantiate module myApp due to:
Missing required parameter 'asUser' in state 'root.login'

Is there anyway to have a global parameter like this with ui.router, without having to mention it in every state and pass it around everywhere?

Was it helpful?

Solution

I would do:

.state("root", {
    url: '/?asUser'
})

You'll still have to handle parameter inheritance on your own, but that should at least make it that parameter valid across all states.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top