Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从api服务获取数据而不刷新浏览器_Javascript_Angular - Fatal编程技术网

Javascript 从api服务获取数据而不刷新浏览器

Javascript 从api服务获取数据而不刷新浏览器,javascript,angular,Javascript,Angular,我使用带angular的spring boot。现在我有一个方法,允许每秒从api服务获取数据,但显示一条消息: js:6185 ERROR-TypeError:您提供了“未定义”流 这是意料之中的。您可以提供一个可观察、承诺、数组或 难以忍受 有什么解决办法吗? 感谢您的帮助您在第一次赋值中引用了this.fiches,因此它的值仍然是未定义的 请尝试按以下方式修复代码: ListAutombilesAuto() { let headers = new HttpHeaders({ 'Aut

我使用带angular的spring boot。现在我有一个方法,允许每秒从api服务获取数据,但显示一条消息:

js:6185 ERROR-TypeError:您提供了“未定义”流 这是意料之中的。您可以提供一个可观察、承诺、数组或 难以忍受

有什么解决办法吗?
感谢您的帮助

您在第一次赋值中引用了
this.fiches
,因此它的值仍然是
未定义的

请尝试按以下方式修复代码:

ListAutombilesAuto() {
  let headers = new HttpHeaders({ 'Authorization': this.jwt });

  this.fiches = this.http.get(this.BaseUrl + '/Automobiles', { headers: headers });

  return this.fiches.pipe
    (
      merge(this.fiches, interval(1000).pipe(switchMap(() => this.fiches)))
    );
}
但实际上,为什么不保持简单:

 ListAutombilesAuto() {

   let headers = new HttpHeaders({ 'Authorization': this.jwt });

   return timer(0, 1000)
     .pipe(
       switchMap(() => this.http.get(this.BaseUrl + '/Automobiles', { headers }))
     )

 }

尝试使用websocket springbootangular@abhinavxeon你这么说是什么意思?你可以用spring boot实现websocket,这样你就可以在没有刷新的情况下获得实时数据,但是websocket的问题并不安全,我认为facebook现在使用http轮询
 ListAutombilesAuto() {

   let headers = new HttpHeaders({ 'Authorization': this.jwt });

   return timer(0, 1000)
     .pipe(
       switchMap(() => this.http.get(this.BaseUrl + '/Automobiles', { headers }))
     )

 }