Najib Marzouk
Najib Marzouk

Reputation: 355

"response.json is not a function" Property 'json' does not exist on type 'Object' angular8

someone can tell me where is the problem.

code stresses on json.

 getPost(){
    this.postService.getAll()
     .subscribe(
       response=>{
       this.posts=response.json();
    },error=>{
      alert('error innattendue')
      console.log(error)
    }
    );
  }

Upvotes: 0

Views: 296

Answers (2)

Ashish Agarwal
Ashish Agarwal

Reputation: 1

this.posts=response; Use like this. This will resolve your issue.

Upvotes: 0

Barkha
Barkha

Reputation: 722

Response should be json that you need, so if you directly use response it should work

 getPost(){
    this.postService.getAll()
     .subscribe(
       response=>{
       this.posts=response;
    },error=>{
      alert('error innattendue')
      console.log(error)
    }
    );
  }

Upvotes: 2

Related Questions