Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不显示从http响应接收的数据_Java_Html_Angular_Typescript_Spring Boot - Fatal编程技术网

Java 不显示从http响应接收的数据

Java 不显示从http响应接收的数据,java,html,angular,typescript,spring-boot,Java,Html,Angular,Typescript,Spring Boot,我有一个服务类型脚本类,如下所示: export class HomeApiService{ apiURL = 'http://localhost:8080/api'; constructor(private http: HttpClient) {} getProfileData():Observable<HomeModelInterface[]>{ return this.http.get<HomeModelInterface[]>(this.ap

我有一个服务类型脚本类,如下所示:

export class HomeApiService{

apiURL = 'http://localhost:8080/api';

constructor(private http: HttpClient) {}

getProfileData():Observable<HomeModelInterface[]>{
        return this.http.get<HomeModelInterface[]>(this.apiURL+'/home');}
}
export class HomeComponent implements OnInit {

public profileData: HomeModelInterface[] | undefined ;

constructor(private homeApiService:HomeApiService) { }

ngOnInit() {
 this.homeApiService.getProfileData().subscribe(data=> {
   this.profileData = data;
   console.log(this.profileData);
});
}
<div *ngFor="let profile of profileData">
 <h1>{{profile.data}}</h1>
</div>
我有如下html文件:

export class HomeApiService{

apiURL = 'http://localhost:8080/api';

constructor(private http: HttpClient) {}

getProfileData():Observable<HomeModelInterface[]>{
        return this.http.get<HomeModelInterface[]>(this.apiURL+'/home');}
}
export class HomeComponent implements OnInit {

public profileData: HomeModelInterface[] | undefined ;

constructor(private homeApiService:HomeApiService) { }

ngOnInit() {
 this.homeApiService.getProfileData().subscribe(data=> {
   this.profileData = data;
   console.log(this.profileData);
});
}
<div *ngFor="let profile of profileData">
 <h1>{{profile.data}}</h1>
</div>
以下是我的ResponseHomeJava类:

public class ResponseHome {

private String data[];
private String errors[];

public String[] getData() {
    return data;
}

public void setData(String[] data) {
    this.data = data;
}

public String[] getErrors() {
    return errors;
}

public void setErrors(String[] errors) {
    this.errors = errors;
}
}
下面是我的前端模型typescript类,用于将json解析为模型类:

export interface HomeModelInterface{
data: string[];
errors: string[];
}
运行chrome时,我看到以下错误: 找不到类型为“object”的不同支持对象“[object]”


您能提供帮助吗?

响应是一个单一实体,一个对象,您正试图在其上运行for循环。如果您查看服务类我正在返回HomeModelInterface getProfileData()的数组,则需要直接使用它。
{{profileData.data}
:可观察的{return this.http.get(this.apirl+'/home');}您的响应返回带有数组的
HomeModelInterface
的单个实例。,因此,不要使用
HomeModelInterface[]
,而是使用
HomeModelInterface
并循环使用
model.data[]