3

The examples given by the angular team only show how to inject Http for typescript.

https://angular.io/docs/js/latest/api/http/Http-class.html

What's the JS equivalent of this:

import {Http, HTTP_PROVIDERS} from 'angular2/http';

and this:

constructor(http: Http) { }
HankScorpio
  • 3,612
  • 15
  • 27

2 Answers2

3

Assuming you're at alpha 49 or newer (you should be at least at beta.0) and you're using the UMD bundles the correct answer is to use ng.http.Http and ng.http.HTTP_PROVIDERS

var App = ng.core.
          Class({
            constructor: [ng.http.Http, function(http) {
              /* Do something with http */
            }]
          });

document.addEventListener('DOMContentLoaded', function() {
  ng.platform.browser.bootstrap(App, [ng.http.HTTP_PROVIDERS]);
});

Here's a plnkr with a working example.

Eric Martinez
  • 31,277
  • 9
  • 92
  • 91
0

If you use ES6 (but not TypeScript), you need to create a getter for the parameters field:

export class SomeClass {
  constructor(http) {}

  static get parameters() {
    return [[Http]];
  }
}
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360