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) { }
2
  • Why do you inject HttpFactory? It's not mentioned in the page you linked to. Commented Feb 28, 2016 at 5:04
  • whoops, too many tabs open. Copied from the wrong one. Thanks! Commented Feb 28, 2016 at 5:06

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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]];
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.