title: Angular2 dependency injection: creating a reference to a property that is initially undefined
body: <p>I'm trying to use Angular2 dependency injection to get a reference to a "Webgl2RenderingContext", which is undefined until I call the createContext function. Is there way to inject the reference into a several different service classes and then set the value after the HTMLCanvasElement is available?</p>
  
  <pre><code>@Injectable()
  export class RenderContext {   
      get context() { return this.render_context; };
  
      constructor() { };
  
      createContext(canvas: HTMLCanvasElement) {
          this.render_context = canvas.getContext("webgl2");
      };
  
      private render_context: WebGL2RenderingContext;
  }
  
  let get_context = () =&gt; {
      return (render_context: RenderContext) =&gt; {
          return render_context.context;
      }
  }
  
  export const webgl2 = new OpaqueToken("webgl2");
  
  export const webgl2_providers = [
      RenderContext,
      {
          provide: webgl2,
          useFactory: get_context(),
          deps: [RenderContext]
      }
  ];
  </code></pre>