1

我正在使用 Spring Boot 和 Webflux 公开一个端点,该端点返回一个无限的数字流,每秒一个:

@GetMapping(value = "/infinitestreamflux", produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
@CrossOrigin(origins = "http://localhost:4200")
public Flux<Long> returnInfiniteStreamFlux() {
    return Flux.interval(Duration.ofSeconds(1))
            .log();
}

如果我从浏览器调用localhost:8080/infinitestreamflux,一切正常。结果在到达时正确显示。

我想使用 Angular 8 归档相同的结果,但页面中没有显示任何内容。

这是我的测试组件:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  infiniteStreamFlux;

  constructor(private http: HttpClient) {}

  ngOnInit(): void {
    this.http.get('http://localhost:8080/infinitestreamflux')
      .subscribe(data => this.infiniteStreamFlux = data);
  }

}

这是我非常简单的模板:

{{infiniteStreamFlux}}

从我的服务器日志中,我可以清楚地看到正在发送结果。从 Chrome 开发工具中,我发现值每秒都会到达,即使它们没有显示在预览选项卡中。最后,页面最终为空。

我该如何解决这个问题?

4

0 回答 0