首页 > 解决方案 > How to get rid of Angular6 typescript error?

问题描述

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[]'

标签: angulartypescriptangular-services

解决方案


您的方法返回类型应该Observable<AgentData>Observable<AgentData[]>


推荐阅读