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$qpromise. 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
$resolvecall - from an invocable that is inherited from a
parentcall to$resolve(or recursively from any ancestor$resolveof that parent).
The return value of
$resolveis 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
parentcall to$resolve(if specified)
The promise will resolve after the
parentpromise (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$resolvepromise is immediately rejected with the same error. A rejection of aparentpromise (if specified) will likewise be propagated immediately. Once the$resolvepromise has been rejected, no further invocables will be called.Cyclic dependencies between invocables are not permitted and will caues
$resolveto 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 theparentinjectable of the same name. This allows inherited values to be decorated. Note that in this case any other injectable in the same$resolvewith 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
$resolvepromise 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
parentcall 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 theresolveproperty of$routeProviderroutes.Parameters:
Name Type Argument Description invocablesObject.<string, Function | string> functions to invoke or
$injectorservices to fetch.localsObject.<string, *> <optional>
values to make available to the injectables
parentPromise.<Object> <optional>
a promise returned by another call to
$resolve.selfObject <optional>
the
thisfor 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
resolvejust callsstudyinternally). See module:$resolve/resolve for details.Parameters:
Name Type Description invocablesObject - Source:
- resolve.js, line 29
Returns:
- Type
- Function