0

I'm a bit confused on how to do a http get call. My app.service is like so:

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';

@Injectable()
export class AppService {
constructor(private http: Http){}
    fetchData(){
    return this.http.get('http://date.jsontest.com/').map(
        (res) = > res.json()
        ).subscribe(
        (data) => console.log(data)
    );
    }
}

This leads to an error of Cannot find name 'res'.

My app.module has the HttpModule.

Having looked through the Angular 2 doc on HTTP requests, they have something like getHeroes (): Observable<Hero[]>. But I am not sure exactly what is contained under the import { Hero } from './hero'; line.

1 Answer 1

1

The line

(res) = > res.json()

that should be

(res) => res.json

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

3 Comments

Wow. I am hopeless. Still, after fixing that, I get another error. This time it says this.http.get(...).map is not a function
Got it. I then had to import import 'rxjs/Rx';
I was just about to say you can just import only the map operator from rxjs instead of the whole rxjs library

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.