Skip to content

Angular Http Subscribe not working

Hi In my Angular Component, i have this code in one of my methods

    resp => { resp = resp.json(); }
    (data) => { this.poeples = data; },
    err =>  console.log(err)

In network tab in chrome dev inspector i saw that my get call returning result, but data is undefined.



The reason it was not working originally, is because you had this:

resp => { resp = resp.json(); }

You are not returning a value. When you use the curly braces, you have to explicitly define a return value. All you had to do was:

resp => { return resp.json(); }

Or remove the braces:

resp => resp.json()