-1
this.http.post(this.url + "/DeptWiseCount", {
  startDate: this.newStartDate,
  endDate: this.newEndDate
}).subscribe(
  data => (
    this.response = JSON.stringify(data),
    console.log(this.response + data[0]["port_count"])
  ),
  error => (
    this.handleError(error)
  )
)

In the above code I am simply want to get data from the API in my console log but it throw an error i.e. Cannot read properties of undefined (reading 'port_count'). I don't know why? Please help me. API output as mention below:

{
  "data": [
    {
      "key": "Pending",
      "total_count": 576871,
      "traffic": 2,
      "traf_count": 502045,
      "port": 1,
      "port_count": 74826
    },
    {
      "key": "Cash",
      "total_count": 305414,
      "traffic": 2,
      "traf_count": 245316,
      "port": 1,
      "port_count": 60098
    }
  ]
}

Thank You

0

1 Answer 1

0

JSON.stringify() is used to convert an object into json string. In your case you shoud be using JSON.parse() to generate a js object from a json response. Hope this helps

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.