我有一个使用 apollo-angular 但 subscribeToMore({}) 方法执行多次的离子角度组件。我确实了解每次进行组件条目时都会执行订阅。我试图为订阅方法分配一个变量,以便在执行此方法后取消订阅,但没有成功,但是我如何使用该变量实际取消订阅?请检查我的示例代码。
export class ViewerComponent implements OnInit, OnDestroy {
queryUpdatesubscribed: any;
queryRef: QueryRef<any>;
constructor() {}
ngOnInit() {
this.manageReactionSubscription()
}
manageReactionSubscription() {
this.queryRef = this.apollo.watchQuery({
query: this.globeService.getModifyPostCommentReactionSubscription(true)
});
this.UpdatePostReactionSubscription();
}
UpdatePostReactionSubscription() {
/*this.queryUpdatesubscribed =*/ this.queryRef.subscribeToMore({
document: this.globeService.getModifyPostCommentReactionSubscription(false),
updateQuery: (prev, { subscriptionData }) => {
if(subscriptionData.data?.modifyPostReactionSubscription !== null) {
const sender = localStorage.getItem('UserID').trim();
// Receive updates here
const update = subscriptionData.data?.ReactionSubscription
console.log('update', update);
}
}
})
}
}