
p.location-badge.
  exported from <a href='../core'>angular2/core</a>
  defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.37/modules/angular2/src/core/di/binding.ts#L41-L229">angular2/src/core/di/binding.ts (line 41)</a>

:markdown
  Describes how_ the <a href='Injector-class.html'><code>Injector</code></a> should instantiate a given token.
  
  See <a href='bind-function.html'><code>bind</code></a>.
  
  ## Example
  
  ```javascript
  var injector = Injector.resolveAndCreate([
    new Binding(String, { toValue: 'Hello' })
  ]);
  
  expect(injector.get(String)).toEqual('Hello');
  ```
  
  

.l-main-section
  h2 Annotations
.l-main-section
  h2 Members
  .l-sub-section
    h3#constructor constructor

    
    pre.prettyprint
      code.
        constructor(token: any, {toClass, toValue, toAlias, toFactory, deps, multi}: {
            toClass?: Type,
            toValue?: any,
            toAlias?: any,
            toFactory?: Function,
            deps?: Object[],
            multi?: boolean
          })
    
    :markdown




  .l-sub-section
    h3#token token

    
    :markdown
      Token used when retrieving this binding. Usually the `Type`.
      
      





  .l-sub-section
    h3#toClass toClass

    
    :markdown
      Binds an interface to an implementation / subclass.
      
      
      
      Because `toAlias` and `toClass` are often confused, the example contains both use cases for
      easy
      comparison.
      
      ```javascript
      
      class Vehicle {}
      
      class Car extends Vehicle {}
      
      var injectorClass = Injector.resolveAndCreate([
        Car,
        new Binding(Vehicle, { toClass: Car })
      ]);
      var injectorAlias = Injector.resolveAndCreate([
        Car,
        new Binding(Vehicle, { toAlias: Car })
      ]);
      
      expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
      expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
      
      expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
      expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
      ```
      
      





  .l-sub-section
    h3#toValue toValue

    
    :markdown
      Binds a key to a value.
      
      
      
      ```javascript
      var injector = Injector.resolveAndCreate([
        new Binding(String, { toValue: 'Hello' })
      ]);
      
      expect(injector.get(String)).toEqual('Hello');
      ```
      
      





  .l-sub-section
    h3#toAlias toAlias

    
    :markdown
      Binds a key to the alias for an existing key.
      
      An alias means that <a href='Injector-class.html'><code>Injector</code></a> returns the same instance as if the alias token was used.
      This is in contrast to `toClass` where a separate instance of `toClass` is returned.
      
      
      
      Because `toAlias` and `toClass` are often confused the example contains both use cases for easy
      comparison.
      
      ```javascript
      
      class Vehicle {}
      
      class Car extends Vehicle {}
      
      var injectorAlias = Injector.resolveAndCreate([
        Car,
        new Binding(Vehicle, { toAlias: Car })
      ]);
      var injectorClass = Injector.resolveAndCreate([
        Car,
        new Binding(Vehicle, { toClass: Car })
      ]);
      
      expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
      expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
      
      expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
      expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
      ```
      
      





  .l-sub-section
    h3#toFactory toFactory

    
    :markdown
      Binds a key to a function which computes the value.
      
      
      
      ```javascript
      var injector = Injector.resolveAndCreate([
        new Binding(Number, { toFactory: () => { return 1+2; }}),
        new Binding(String, { toFactory: (value) => { return "Value: " + value; },
                              dependencies: [Number] })
      ]);
      
      expect(injector.get(Number)).toEqual(3);
      expect(injector.get(String)).toEqual('Value: 3');
      ```
      
      





  .l-sub-section
    h3#dependencies dependencies

    
    :markdown
      Used in conjunction with `toFactory` and specifies a set of dependencies
      (as `token`s) which should be injected into the factory function.
      
      
      
      ```javascript
      var injector = Injector.resolveAndCreate([
        new Binding(Number, { toFactory: () => { return 1+2; }}),
        new Binding(String, { toFactory: (value) => { return "Value: " + value; },
                              dependencies: [Number] })
      ]);
      
      expect(injector.get(Number)).toEqual(3);
      expect(injector.get(String)).toEqual('Value: 3');
      ```
      
      





  .l-sub-section
    h3#multi multi

    
    :markdown
      Used to create multiple bindings matching the same token.
      
      
      
      ```javascript
      var injector = Injector.resolveAndCreate([
        new Binding("Strings", { toValue: "String1", multi: true}),
        new Binding("Strings", { toValue: "String2", multi: true})
      ]);
      
      expect(injector.get("Strings")).toEqual(["String1", "String2"]);
      ```
      
      Multi bindings and regular bindings cannot be mixed. The following
      will throw an exception:
      
      ```javascript
      var injector = Injector.resolveAndCreate([
        new Binding("Strings", { toValue: "String1", multi: true}),
        new Binding("Strings", { toValue: "String2"})
      ]);
      ```
      
      




