每当我导航到该页面时,订阅就增加了,我面临着取消订阅阿波罗的问题。 预期的行为:onDestroy应该取消所有订阅。 我自己的信念:我确实认为问题出在我从Apollo批量获取数据的方式上,我认为在加载的每个数据上都会创建一个新的订阅实例。因此,我需要取消订阅所有我无法成功执行的onDestroy实例。请任何帮助将不胜感激。
`
next = 150;
offset = 0;
invoiceHolder = [];
getInvoices() { // Simulate old invoioce load
this.invoicesSub = this.apollo.watchQuery<any>({
query: invoices,
variables: {
offset: this.offset,
first: this.next
}
}).valueChanges
.subscribe(res => {
const totalCount = res.data.company.invoices.totalCount;
this.offset = this.offset + this.next;
this.invoiceAvailable.next({available: this.offset, totalCount});
const result_array = [];
this.invoiceHolder = result_array.concat(this.cleanData(res.data.company.invoices));
this.invoices.next(this.invoiceHolder);
});
}
ngOnDestroy() {
(this.invoicesSub !== null) && this.invoicesSub.unsubscribe();
}
`