Javascript 角度前端未对烧瓶应用程序进行休止调用
我在这个url中运行了一个flask应用程序 我使用return jsonify(data)返回json格式的数据Javascript 角度前端未对烧瓶应用程序进行休止调用,javascript,angular,rest,Javascript,Angular,Rest,我在这个url中运行了一个flask应用程序 我使用return jsonify(data)返回json格式的数据 this.mainService.getVamData(this.paramData.Eid,'SectionA') .subscribe(result=>{ this.data=result; console.log(this.data); }) 我从angular application main-service.ts文件中调用此url,如下所示 public
this.mainService.getVamData(this.paramData.Eid,'SectionA')
.subscribe(result=>{
this.data=result;
console.log(this.data);
})
我从angular application main-service.ts文件中调用此url,如下所示
public getVamData(id,section): Observable<any> {
try {
console.log("I am here getVAM");
return this.http.get('http://localhost:5000/SectionA')
.map((response: Response) => {
console.log("I am here getVAM2");
return response.json();
}
);
}
catch(e) {
console.log('Error:', e);
} }
public getVamData(id,section):可观察{
试一试{
log(“我在这里getVAM”);
返回此.http.get('http://localhost:5000/SectionA')
.map((响应:响应)=>{
log(“我在这里获取VAM2”);
返回response.json();
}
);
}
捕获(e){
log('Error:',e);
} }
但是url没有命中flask应用程序。请让我知道我遗漏了什么。您必须订阅Observable,因为Observable是惰性加载的。 如果您在其他地方(如组件)使用getVamData()服务方法,请在那里订阅。 像这样使用
this.mainService.getVamData(this.paramData.Eid,'SectionA')
.subscribe(result=>{
this.data=result;
console.log(this.data);
})
... 您在哪里订阅?我在vam_component.ts文件构造函数中订阅它(公共路由:ActivatedRoute,公共mainService:MainServiceService){this.route.params.subscribe(params=>{this.paramData=params;console.log(this.paramData)this.data=this.mainService.getVamData(this.paramData.Eid,'SectionA');console.log(this.data);我做了更改,但仍然无法访问它。我有两个应用程序django在8080端口运行,flask在5000端口运行。我可以调用django rest api url,但不能调用flask api url。我是否应该在配置文件中进行一些更改,以访问在不同端口上运行的两个应用程序?我已将flask应用程序部分移到Django rest框架工作,现在我在main-service.ts中得到响应,但我在
this.mainService.getVamData(this.paramData.Eid,'SectionA').subscribe(result=>{this.data=result;console.log(this.data);},error=>console.log(error))现在我得到了响应,但subscribe是递归运行的。我想在一轮迭代后将我的json响应存储在一个变量中,然后处理json数据,比如var temp=this.http.get('http://localhost:8000/vamcomponent/)
请告诉我怎么做。让classes=this.data[1].classes;因为您的响应数据是数组,而classes是索引1处字段的名称。现在使用classes变量进行循环,让我知道它是否对您有效