Skip to content

resolve doesn't work when the factory in the map is a string #449

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
jnizet opened this issue Sep 19, 2013 · 0 comments
Closed

resolve doesn't work when the factory in the map is a string #449

jnizet opened this issue Sep 19, 2013 · 0 comments

Comments

@jnizet
Copy link

jnizet commented Sep 19, 2013

When the resolve map of a state is defined as follows:

resolve: {
    value: 'foo'
}

then 'foo' is supposed to be an alias to a service, that will be called by ui-router, and return a value or a promise. However, that doesn't work (
Link to plunkr).

The line 130 of angular-ui-router.js is suspect:

plan.push(key, [ function() { return $injector.get(key); }], NO_DEPENDENCIES);

Indeed, instead of getting the service from the $injector using the value of the map attribute, it gets it using the key.

I think the following lines:

  if (isString(value)) {
    plan.push(key, [ function() { return $injector.get(key); }], NO_DEPENDENCIES);
  } else {
    var params = $injector.annotate(value);
    forEach(params, function (param) {
      if (param !== key && invocables.hasOwnProperty(param)) visit(invocables[param], param);
    });
    plan.push(key, value, params);
  }

should be replaced with:

  var fn = value;
  if (isString(value)) {
    fn = $injector.get(value);
  }
  var params = $injector.annotate(fn);
  forEach(params, function (param) {
    if (param !== key && invocables.hasOwnProperty(param)) visit(invocables[param], param);
  });
  plan.push(key, fn, params);
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

1 participant