.subscribe 函数不作为输入参数传递

问题描述

我有这个函数可以从组件中的服务中获取一个数组,id 喜欢通过@Input 将这个新获取的数组传递给另一个组件。在服务调用中,数组完美填充,但如果我 console.log 它在其他任何地方,它的空数组。请帮忙。 这是我的 array-getter 函数,它在 component1 中的 ngOnInIt 和 ngOnChanges 上调用

getSignOffs(){
    this.signoffsService
      .getSignOffs(
        Number(this.workpaperSetId),SignOffElementTypeNumber.WorkpaperSetUserAdjustments,this.workpaperId.toString()
      )
      .subscribe(
        sign => {
          //reset array
          let signoffsUsable = [];
          
          //here we are getting the array of signoff history from the collection to use for displaying the circles
          if (sign[0]) {
            const arrayOfSignOffs: SignOffSearchModel[] = sign[0].signOffs;
            for (let i = 0; i < arrayOfSignOffs.length; i++) {
              signoffsUsable.push(arrayOfSignOffs[i]);
            }
            this.signOffCollection = signoffsUsable;
          }
        },error => {
          this.notificationService.error(this.errorMessage);
          this.handleError(error);
        }
      );
  }

这里的 this.signOffCollection 是数组 id 想要传递给 component2 的

<app-signoff
        class="d-flex align-items-center mt-1 mb-3"
        [signOffCollection]="signOffCollection"
      ></app-signoff>

再次,服务调用中的 console.log 获取正确的数组,但在其他任何地方都是 []

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)