简体   繁体   English

如何从 Angular 承诺返回正文?

[英]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.

相关问题 如何从 Angular 向 Spring 引导发送参数(在正文内,无标题)? - How to send a parameter (within body, no headers) from Angular to Spring Boot? 从java中的HttpResponse读取正文返回不稳定? - Read body return from HttpResponse unstable in java? 如何在响应正文中返回 WireMock 服务器端口 - How to return WireMock server port in a response body 如何在请求范围的 bean 中返回一个空主体 - How to return an empty body in request scoped bean 如何在函数体中使用if和switch语句返回 - how to return with if and switch statements in function body 如何在响应正文中返回 ConstraintViolationException 消息? - How to return the ConstraintViolationException messages in the response body? 如何正确地将地图从角度客户端发送到请求正文中的spring boot controller? 收到的地图始终为空 - How to properly send map from angular client to spring boot controller in request body? Received map is always empty 如何从Java servlet返回带有角度的JSON数据? - How to return JSON data with angular from a java servlet? 从Java中的Promise [JsonNode]获取JsonNode并返回该值 - Obtain the JsonNode from a Promise[JsonNode] in Java and return that value Wiremock - 从 URL 中获取一个字符串,对其进行修改并将其作为正文的一部分返回 - Wiremock - Grab a string from the URL, modify it and return it as part of the body
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM