Skip to content

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

Closed
@jnizet

Description

@jnizet

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions