title: Using D3.js with Angular 2
body: <p>I have successfully integrated Angular 2 (Alpha 44) with D3.js:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Angular 2 QuickStart&lt;/title&gt;
  &lt;script src="../node_modules/systemjs/dist/system.src.js"&gt;&lt;/script&gt;
  &lt;script src="../node_modules/angular2/bundles/angular2.dev.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"&gt;&lt;/script&gt;
  &lt;script&gt;
    System.config({packages: {'app': {defaultExtension: 'js'}}});
    System.import('app/app');
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;my-app&gt;Loading...&lt;/my-app&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>app.js:</p>
  
  <pre><code>/// &lt;reference path="./../../typings/tsd.d.ts" /&gt;
  
  import {Component, bootstrap, ElementRef} from 'angular2/angular2';
  
  @Component({
    selector: 'my-app',
    template: '&lt;h1&gt;D3.js Integrated if background is yellow&lt;/h1&gt;',
    providers: [ElementRef]
  })
  class AppComponent { 
    elementRef: ElementRef;
  
    constructor(elementRef: ElementRef) {
     this.elementRef = elementRef;
    }
  
  afterViewInit(){
      console.log("afterViewInit() called");
      d3.select(this.elementRef.nativeElement).select("h1").style("background-color", "yellow");
    }
  }
  bootstrap(AppComponent);
  </code></pre>
  
  <p>Everything is working fine. But Angular 2 documentation for ElementRef states the following:</p>
  
  <blockquote>
    <p>Use this API as the last resort when direct access to DOM is needed. Use templating and data-binding provided by Angular instead. Alternatively you take a look at {@link Renderer} which provides API that can safely be used even when direct access to native elements is not supported. Relying on direct DOM access creates tight coupling between your application and rendering layers which will make it impossible to separate the two and deploy your application into a web worker.</p>
  </blockquote>
  
  <p>Now the question arises how to integrate D3.js with the Renderer API's?</p>