I\'ve been playing with Angular 2 Quickstart.
How can I use/import http module in Angular 2?
I\'ve looked at Angular 2 Todo\'s.js, but it doesn\'t use the ht
Its already in angular2, so you dont need to put anything in package.json
You just have to import and inject it like this. (this is a Stuff service with a methodThatUsesHttp() that just logs the response)
import {XHR} from 'angular2/src/core/compiler/xhr/xhr';
export class Stuff {
$http;
constructor($http: XHR) {
this.$http = $http;
}
methodThatUsesHttp() {
var url = 'http://www.json-generator.com/api/json/get/cfgqzSXcVu?indent=2';
this.$http.get(url).then(function(res) {
console.log(res);
}, function(err) {
console.log(err);
});
}
}