我有一个Python Flask后端服务,它在API上使用GET
调用时提供一个JSON,如下所示:
查询:
curl -XGET http://localhost:5000/bizLocations
回应:
^{pr2}$我真的只想在一个下拉列表中显示通过Angular构建的前端列表
代码段:
^{3}$我创建了一个服务:
component.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class ComponentService {
private backEnd = 'http://localhost:5000';
constructor(private http: HttpClient) { }
getBizLocations() {
return this.http.get(`${this.backEnd}/bizLocations`);
}
}
在组件中,我按如下方式调用服务:
ngOnInit() {
this.getBusinessLocations();
}
getBusinessLocations() {
this.componentService.getBizLocations()
.subscribe((data: any) => {
console.log(data);
this.locations = data.locations;
});
}
是什么导致了这个错误?是与CORS
或{
这个问题实际上与CORS有关。在
我用以下方法解决了这个问题:
然后在后端代码中:
^{pr2}$这样可以完全删除错误,并且控制台能够从后端记录输出。在
相关问题 更多 >
编程相关推荐