44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
 | 
						|
p.location-badge.
 | 
						|
  exported from <a href='../di'>angular2/di</a>
 | 
						|
  defined in <a href="https://github.com/angular/angular/tree/3a0410a/modules/angular2/src/di/exceptions.ts#L69-L103">angular2/src/di/exceptions.ts (line 69)</a>
 | 
						|
 | 
						|
:markdown
 | 
						|
  Thrown when trying to retrieve an async <a href='Binding-class.html'><code>Binding</code></a> using the sync API.
 | 
						|
  
 | 
						|
  ## 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);
 | 
						|
  ```
 | 
						|
  
 | 
						|
  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.
 | 
						|
  
 | 
						|
.l-main-section
 | 
						|
  h2 Members
 | 
						|
  .l-sub-section
 | 
						|
    h3 constructor
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        constructor(key)
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 |