How can I get data return from post service as I am geeting subscription always. Even i try to convert in my app component I am not able to it.
如何从邮寄服务中获取数据,因为我总是订阅。即使我尝试在我的应用程序组件中转换我也无法做到。
facility_sevice.ts
facility_sevice.ts
saveFacility(facility) {
const headers = new Headers({'Content-Type': 'application/json'});
return this.http.post('http://localhost:8000/saveFacility',
facility, headers)
.subscribe(
(response: Response) => {
return response.json();
},
(error) => {
return error.json();
}
);
}
facility_component.ts
facility_component.ts
savePatient() {
const response =
this.facilityService.saveFacility(this.facilityForm.value)
console.log(response);
}
I am getting sbscription object but I want to return as json.
我正在获取sbscription对象,但我想以json的身份返回。
1 个解决方案
#1
3
RxJS library provides Observable operators which you can use to manipulate the data being emitted like map, filter.
RxJS库提供了Observable操作符,您可以使用它来操作像map,filter这样的数据。
Try using map operator:
尝试使用map运算符:
saveFacility(facility) {
const headers = new Headers({'Content-Type': 'application/json'});
return this.http.post('http://localhost:8000/saveFacility', facility, headers)
.map(response => response.json())
.subscribe((response: Response) => {
return response.json();
},
(error) => {
return error.json();
}
);
}
#1
3
RxJS library provides Observable operators which you can use to manipulate the data being emitted like map, filter.
RxJS库提供了Observable操作符,您可以使用它来操作像map,filter这样的数据。
Try using map operator:
尝试使用map运算符:
saveFacility(facility) {
const headers = new Headers({'Content-Type': 'application/json'});
return this.http.post('http://localhost:8000/saveFacility', facility, headers)
.map(response => response.json())
.subscribe((response: Response) => {
return response.json();
},
(error) => {
return error.json();
}
);
}