如何解决.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 举报,一经查实,本站将立刻删除。