Angular 如何从Api中提取数据到组件中的数组

Angular 如何从Api中提取数据到组件中的数组,angular,angular-services,Angular,Angular Services,在下面给出的代码中,如何在数据中获取服务的值,稍后我们将该数据传输到数组employee- 请解释:(data=>this.employee=data) 员工:任何[]; getEmployees():可观察{ 返回this.http.get(this.\uURL)。} this.empService.getEmployees() .subscribe(数据=>this.employee=数据); 另外,在代码中:data=>this.employee=data。数据是否包含传输到this.e

在下面给出的代码中,如何在数据中获取服务的值,稍后我们将该数据传输到数组employee- 请解释:(data=>this.employee=data)

员工:任何[];
getEmployees():可观察{
返回this.http.get(this.\uURL)。}
this.empService.getEmployees()
.subscribe(数据=>this.employee=数据);

另外,在代码中:data=>this.employee=data。数据是否包含传输到this.employee(数组)的所有值和。我们为什么在这里使用FAT ARROW=>所有内容都在

通过观察,您可以进行异步操作,这里您可以从API之类的东西获取一些数据

可观察对象有一个方法
subscribe()
,当调用此方法时,api调用完成。这个subscribe方法有3个参数,它们是3个回调函数

第一个是在您的案例中解析数据时,这是:
data=>this.employee=data


第二个是当可观察对象无法获得一些数据时,最后一个是当一切都完成时。

你的问题到底是什么?这是代码中
可观察对象的
方法:data=>This.employee=data。数据是否包含传输到this.employee(数组)的所有值和。为什么我们使用FAT ARROW=>这里这只是经典的ARROW函数,请阅读
  employee: any[];

getEmployees(): Observable<IEmployee[]> {
  return this.http.get<IEmployee[]>(this._url). }

this.empService.getEmployees()
.subscribe(data => this.employee = data);