Service (ui-util
). Manages resolution of (acyclic) graphs of promises.
- Source:
- resolve.js, line 1
Requires
- module:$q
- module:$injector
Methods
-
resolve(invocables, locals, parent, self) → {Promise.<Object>}
-
Resolves a set of invocables. An invocable is a function to be invoked via
$injector.invoke()
, and can have an arbitrary number of dependencies. An invocable can either return a value directly, or a$q
promise. If a promise is returned it will be resolved and the resulting value will be used instead. Dependencies of invocables are resolved (in this order of precedence)- from the specified
locals
- from another invocable that is part of this
$resolve
call - from an invocable that is inherited from a
parent
call to$resolve
(or recursively from any ancestor$resolve
of that parent).
The return value of
$resolve
is a promise for an object that contains (in this order of precedence)- any
locals
(if specified) - the resolved return values of all injectables
- any values inherited from a
parent
call to$resolve
(if specified)
The promise will resolve after the
parent
promise (if any) and all promises returned by injectables have been resolved. If any invocable (or$injector.invoke
) throws an exception, or if a promise returned by an invocable is rejected, the$resolve
promise is immediately rejected with the same error. A rejection of aparent
promise (if specified) will likewise be propagated immediately. Once the$resolve
promise has been rejected, no further invocables will be called.Cyclic dependencies between invocables are not permitted and will caues
$resolve
to throw an error. As a special case, an injectable can depend on a parameter with the same name as the injectable, which will be fulfilled from theparent
injectable of the same name. This allows inherited values to be decorated. Note that in this case any other injectable in the same$resolve
with the same dependency would see the decorated value, not the inherited value.Note that missing dependencies -- unlike cyclic dependencies -- will cause an (asynchronous) rejection of the
$resolve
promise rather than a (synchronous) exception.Invocables are invoked eagerly as soon as all dependencies are available. This is true even for dependencies inherited from a
parent
call to$resolve
.As a special case, an invocable can be a string, in which case it is taken to be a service name to be passed to
$injector.get()
. This is supported primarily for backwards-compatibility with theresolve
property of$routeProvider
routes.Parameters:
Name Type Argument Description invocables
Object.<string, Function | string> functions to invoke or
$injector
services to fetch.locals
Object.<string, *> <optional>
values to make available to the injectables
parent
Promise.<Object> <optional>
a promise returned by another call to
$resolve
.self
Object <optional>
the
this
for the invoked methods- Source:
- resolve.js, line 209
Returns:
Promise for an object that contains the resolved return value of all invocables, as well as any inherited and local values.
- Type
- Promise.<Object>
- from the specified
-
study(invocables) → {Function}
-
Studies a set of invocables that are likely to be used multiple times. $resolve.study(invocables)(locals, parent, self) is equivalent to $resolve.resolve(invocables, locals, parent, self) but the former is more efficient (in fact
resolve
just callsstudy
internally). See module:$resolve/resolve for details.Parameters:
Name Type Description invocables
Object - Source:
- resolve.js, line 29
Returns:
- Type
- Function