angular-cn/public/docs/js/latest/api/di/AsyncBindingError-class.jade

44 lines
1.1 KiB
Plaintext
Raw Normal View History

2015-04-19 13:53:18 -07:00
2015-04-22 08:06:51 -07:00
p.location-badge.
2015-06-01 22:51:00 -07:00
exported from <a href='../di'>angular2/di</a>
defined in <a href="https://github.com/angular/angular/tree/master/modules/angular2/src/di/exceptions.ts#L69-L103">angular2/src/di/exceptions.ts (line 69)</a>
2015-04-19 13:53:18 -07:00
:markdown
2015-06-01 22:51:00 -07:00
Thrown when trying to retrieve an async <a href='Binding-class.html'><code>Binding</code></a> using the sync API.
2015-04-19 13:53:18 -07:00
## Example
```javascript
var injector = Injector.resolveAndCreate([
bind(Number).toAsyncFactory(() => {
return new Promise((resolve) => resolve(1 + 2));
}),
bind(String).toFactory((v) => { return "Value: " + v; }, [String])
]);
injector.asyncGet(String).then((v) => expect(v).toBe('Value: 3'));
expect(() => {
injector.get(String);
}).toThrowError(AsycBindingError);
```
2015-06-01 22:51:00 -07:00
The above example throws because `String` depends on `Number` which is async. If any binding in
the dependency graph is async then the graph can only be retrieved using the `asyncGet` API.
2015-04-19 13:53:18 -07:00
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
2015-04-20 13:57:43 -07:00
constructor(key)
2015-04-19 13:53:18 -07:00
:markdown
2015-06-01 22:51:00 -07:00
2015-04-19 13:53:18 -07:00