无法从angular调用的Web API操作获取结果

时间:2019-02-08 03:30:33

标签: angular asp.net-web-api angular6

我试图通过POST请求将用户的电子邮件(以Angular格式)传递到WebApi,以获取UserProfile详细信息,但是我无法获取数据。我收到此错误:输入意外结束。

以下是进行呼叫的方法:

getUserProfile(resourceEmail: string): Observable<any> {
debugger
return this.http.post<UserVM>(this.getAPI('FetchUserProfile')+'/? emailId='+resourceEmail,
  this.httpOptions).pipe(
    map(data => data),
    catchError(this.handleError<any>())
  );
 }

控制器动作代码

    [System.Web.Mvc.HttpPost]
    [System.Web.Mvc.Route("ApiWithAction")]
    public HttpResponseMessage FetchUserProfile(string emailId)
    {
        try
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, _userProfileService.GetUserProfile(emailId));
            return response;
        }
        catch (Exception ex)
        {
            //client.TrackException(ex.InnerException);
            return null; //need to check and confirm what needs return to UI               
        }
    }

订阅代码

 getBookingList() {
this.bookingListSubscription = this.restService.getCompletedListForGrid(this.booking).subscribe(
  data => {

    this.bookingList = data;

    this.bookingList.forEach((element) => {
      element.StartDate = new Date(element.StartDate),
        element.EndDate = new Date(element.EndDate);
    });
    this.gridData = this.bookingList;
    this.spinner.hide();
  });

Error

1 个答案:

答案 0 :(得分:0)

可能是您以错误的方式分配值,最好分配--

this.restService.getUserProfile("")
 .subscribe(data => {
    this.bookingListSubscription
    .... other code
 });