Angular 使用api时,列表在角度中为空

Angular 使用api时,列表在角度中为空,angular,api,Angular,Api,我试图使用一个api,即带有邮递员返回数据的“api”,但当我从角度使用时,数组是空的 我的服务 import { Injectable } from '@angular/core'; import { HttpClient, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; @Injectable({ provide

我试图使用一个api,即带有邮递员返回数据的“api”,但当我从角度使用时,数组是空的

我的服务

    import { Injectable } from '@angular/core';
    import { HttpClient, HttpEvent, HttpHandler, HttpInterceptor, 
           HttpRequest } from '@angular/common/http';

    @Injectable({
      providedIn: 'root'
    })
    export class ServicioService {

      constructor(private http: HttpClient) { }

      public getAll() {
        let url = 'https://localhost:44388/api/places';
        return this.http.get(url);  
        } 
    }


[it´s the code that use my api][1]

当然,你可以试试看它是否有效

为您服务:

public getAll() {
    let url = `${environment.base_url}/api/Places`;

    return this.httpC.get(url);
}
然后调用组件

this.serplaceService.getAll().subscribe(
   (data) => this.lstPLaces = data,
   error => this.error = error
)
注:

读取完整响应时,响应主体不会返回所有 您可能需要的数据。有时服务器返回特殊的头或状态 用于指示对系统重要的某些条件的代码 应用程序工作流

告诉HttpClient您希望使用“观察”选项获得完整响应:

return this.httpC.get(url, { observe: 'response' });

如何调用
getAll()
?getPlaces(){let observer={next:x=>this.lstsplaces=x,error:err=>this.serplaceService.handleError(err)};this.serplaceService.getAll().subscribe(observer)}嗨,为你的响应而加油,我写了代码和同样的代码,当我尝试读取this.serplaceService.getAll()之后的变量时,subscribe((数据)=>this.lstPLaces=data,error=>this.error=error)变量this.lstPLaces和this.error是未定义的。我如何发送它,在哪里可以发送代码,这是非常小的空间名称空间MyTime.ApiControl.controller{使用Microsoft.AspNetCore.Mvc;使用MyTimes.Bl;使用MyTimes.Common.Models;使用Newtonsoft.Json;使用System.Collections.Generic;使用System.Linq;[Route(“api/[controller]”][ApiController]公共类placecontroller:ControllerBase{[HttpGet]public JsonResult Get(){var lstPlaces=JsonConvert.DeserializeObject(new-BLPlaces().FindAll());lstPlaces.Remove(lstPlaces.Where(X=>X.PlaceId==0.FirstOrDefault());return new-JsonResult(lstPlaces);}}}}}您能更新您的问题中的代码吗?我怎么看得到