Angular App在会话中首次花费大量时间从API调用加载数据

时间:2018-11-28 18:59:46

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

我是Angular的新手,正在使用Angular 6构建应用程序。我面临的问题是,该应用程序花费大量时间从我的第一个API调用中加载数据。尽管在随后的请求中数据显示非常快。有什么方法可以快速加载数据,甚至在加载数据时以块的形式显示数据?

这就是我从服务中的webApi获取数据的方式:-

getByKey(key:string) :Observable<IClient[]>
 {
   return this._http.get<IClient[]>(this.baseUrl+"/getByKey/"+key);
 }

这是我调整服务方法的方式:-

public getSearchKey(): void {
  this._clientService.getByKey(this.searchKey).subscribe(clientData => this.clients = clientData, error => {
      console.error(error)
        },()=>this.loaded=true);

}

使用this.client我正在表中显示数据。

谢谢

1 个答案:

答案 0 :(得分:-1)

您可以使用Observable:here 您可以订阅/取消订阅和管理每个收到的值。