2

我的代码块ngOnInit如下:

this.subscriptions = this.formService.getFormFromApi(this.formId)
      .pipe(
        concatMap(theForm => this.formService.getFormStructure(theForm))
      ).pipe(
        take(1),
        tap(tree => { this.treeNodeData = tree; }),
        (finalize(() => this.isTreeLoading = false))
      ).subscribe();
...
    this.subscriptions.add(
      combineLatest(
        this.fileService.getFiles(this.formId),        
        this.formService.questionsList
      ).pipe(
        tap(arrResult => {
          this.fileData = arrResult[0];          
          this.test = arrResult[1];
          console.log("fired.")
        })
      ).subscribe()
    );
...

想法如下:
当列定义由 确定更改时questionsList,我希望重新渲染表格。我打算通过再次获取文件来做到这一点(不要担心重复调用 http。当它工作时,我将用更有效的东西替换逻辑)

但是,即使一直在BehaviorSubject更改值(要在表中显示的列),结果也不会刷新。基本上,“fired”在页面第一次加载后不会运行。

为什么会这样?是因为http调用已经完成而questionsList没有吗?我的想法是combineLatest只要其中一个可观察对象发出一些东西就会触发?

4

1 回答 1

1

我已经解决了这个问题。删除后this.subscriptions.add()它按预期工作。

// this.subscriptions.add(
      combineLatest(
        this.fileService.getFiles(this.formId),        
        this.formService.questionsList
      ).pipe(
        tap(arrResult => {
          this.fileData = arrResult[0];          
          this.test = arrResult[1];
          console.log("fired.")
        })
      ).subscribe()
   // );

如果某些 rxjs 大师可以解释这种现象,请添加或编辑此答案。

于 2020-02-13T04:16:34.340 回答