
.l-main-section
  h2(class="function export") bind

  
  pre.prettyprint
    code.
      bind(token: any) : BindingBuilder
  

  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#L265-L305">angular2/src/core/di/binding.ts (line 265)</a>

  :markdown
    Provides an API for imperatively constructing <a href='Binding-class.html'><code>Binding</code></a>s.
    
    To construct a <a href='Binding-class.html'><code>Binding</code></a>, bind a `token` to either a class, a value or a factory function.
    See <a href='BindingBuilder-class.html'><code>BindingBuilder</code></a> for more details.
    
    The `token` is most commonly an <a href='angular2/di/OpaqueToken'>OpaqueToken</a> or a class.
    
    `bind` is only relevant for JavaScript. For Dart use the <a href='Binding-class.html'><code>Binding</code></a> constructor.
    
    ## Example
    
    ```typescript
    // inj.get(MyClass) would instantiate MyClass
    bind(MyClass).toClass(MyClass);
    
    // inj.get(MyClass) === 'my class'
    bind(MyClass).toValue('my class');
    
    // inj.get(MyClass) would instantiate the depenency and call the factory function with the
    // instance
    bind(MyClass).toFactory(dep => new MyClass(dep), [DepClass]);
    
    // inj.get(MyOtherClass) === inj.get(MyClass)
    bind(MyOtherClass).toAlias(MyClass);
    ```
    
    ```dart
    var binding = new Binding(MyClass, toClass: MyClass);
    var binding = new Binding(MyClass, toValue: 'my class');
    var binding = new Binding(MyClass, toFactory: (dep) => new MyClass(dep),
                              dependencies: [DepClass]);
     var binding = new Binding(MyOtherClass, toAlias: MyClass);
    ```
    
    


