Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsubscribing in Angular NGXS

I’m new to NGXS in Angular and I have read that you don’t need to unsubscribe when you use the async pipe. However I’m also subscribing from the queryParams and I’m subscribing from the dispatches action. Do I need to unsubscribe from this 2 codes below?

this.route.queryParamMap
 .pipe(map(params => params.get('page')))
 .subscribe((page: any) => {
   this.page = page;
   console.log(page);
  });

this.store.dispatch(new AddEmployee(form.value)).subscribe(() => {
 form.reset();
 this.modalReference.close(); 
like image 210
Joseph Avatar asked Sep 05 '25 03:09

Joseph


1 Answers

The answer is don't need to unsubscribe from these two set of codes. Because routes are handled by Angular and second, the store is handled by ngxs. No need to unsubscribe. Unsubscribe only when using rxjs

GitHub: Does I need to unsubscribe on distaching actions?

amcdnl commented on Jul 3, 2018

Nope. Its handled for you.,

like image 157
Joseph Avatar answered Sep 07 '25 19:09

Joseph