2

I'm building an angular 6 project with typescript 3.1.2. I'm calling a restful API that returns a JSON data set with a label name data. I'm getting the below error but the website works perfectly without any console error. Is this a bug or I'm I doing something wrong?

error TS2339: Property 'data' does not exist on type 'AgentData[]'.

Json Data: enter image description here

Here is my class: enter image description here

Here is my Service: enter image description here

Here is my Agent Component subscribing to the service. enter image description here

This is the error from VS Code Editor:

[ts] Property 'data' does not exist on type 'AgentData[]'
1
  • I voted to close this question, because the code is in the form of images, not text. Commented Oct 10, 2018 at 16:59

2 Answers 2

1

your method return type should be Observable<AgentData> instead of Observable<AgentData[]>

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

Comments

0

your are looking for resp.data where resp is an array. you should be looking for resp[0].data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.