[英]How to return body from a Angular promise?
How to return the body from the response received from an angular promise.如何从 Angular Promise 收到的响应中返回正文。 Below is the output.下面是输出。 I want the data from the third body which i am not sure how can i retreive.我想要来自第三个机构的数据,我不确定如何检索。 Again i am not sure why i am getting nested body for a promise.再次,我不确定为什么我要嵌套身体以获得承诺。 Please advise.请指教。
Below code :下面的代码:
fetch = () => {
debugger;
let url = `${environment.api}${Paths.FetchData}`+this.userId;
let req: HttpRequest<any> = new HttpRequest("Get", url, {
headers: new HttpHeaders({
"Accept": "text/html",
"Content-Type": "text/html"
}),
responseType: "json"
});
this.http.request(req).toPromise().then(r => {
debugger;
console.log(r);
return r;
});
}
Backend Code :后端代码:
@RequestMapping(value = "/fetchData/{userId}", method = RequestMethod.GET)
public String fetchData(@PathVariable("userId") String userId) {
System.out.println("calling00");
if (!MyUtility.checkNullOrZero(Long.valueOf(userId))) {
try {
return service.fetchData(Long.valueOf(userId));
} catch (Exception e) {
log.error("Error ", e);
return null;
}
}
return null;
}
import { HttpClient } from '@angular/common/http';
constructor(private readonly http: HttpClient) { }
getRequest(){
return this.http.get(reqUrl).toPromise()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.