I am trying to do a simple GET
request with Http in Angular 2, following this TUTORIAL and some other more up to date resources.
After successfully injecting the http component, I wrote the following code
constructor(@Inject(Http) /* remove @Inject once @Injectable works */ public http:Http){
http.get('https://api.travis-ci.org/config').toPromise().then((response => console.log(response.json().data) )
// .map(res => res.text())
// .subscribe(
// data => console.log(data),
// err => console.error(err),
// () => console.log('Random Quote Complete')
// );
}
As you can see there are a lot of comments as I have tried several combinations. I am getting these errors
http.get(...).map is not a function(…)
if I try to use map
Request header field X-XSRF-TOKEN is not allowed by Access-Control-Allow-Headers in preflight response.
for anything else.. (toPromise) for example.
how can I make it work?
If I use fetch
, the call works.. so it has to be something in angular.