1

I am getting the below errors for the below function in Angular 6

public getList() {
        return this.http.get(environment.serverUrl +'/vmsdata/v1/tftoport/customer/1001')
            .toPromise()
            .then(response => response.json()
            .then(json => {
                console.log('data', json.items);
                return json.items;
            });
    }

For the line .then(response => response.json(), Error is [ts] Property 'json' does not exist on type 'Object'.

For the line .then(json => { Error is [ts] Parameter 'json' implicitly has an 'any' type.

halfer
  • 19,824
  • 17
  • 99
  • 186
Raja
  • 3,477
  • 12
  • 47
  • 89
  • There's at least one closing parentheses `)` missing in your code. – Robby Cornelissen Aug 02 '18 at 01:23
  • Is `this.http` an instance of `Http` or `HttpClient`? And you can get rid of the second error by changing `json => ...` to `(json: any) => ...`, or you can disable noImplicityAny in your tsconfig.json – matmo Aug 02 '18 at 01:23
  • In angular 6, the old, deprecated `Http` class does not exist anymore, so it's necessarily `HttpClient`; which converts retrieved data to json by default. So you don't need the `.then(response => response.json())` line – David Aug 02 '18 at 08:11

1 Answers1

1

In Angular 6 You don't need to map data into json because angular 6 provide json by default.

Ravindra Gupta
  • 91
  • 3
  • 13