0

How can I unsubscribe from this using take operator?

constructor(/*params*/) {
  let id = this.route.snapshot.paramMap.get('id');
  if (id) this.productService.get(id).valueChanges().subscribe(p => this.product = p);
}
Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
filip
  • 45
  • 9

1 Answers1

0

If you mean the take(1) operator to only fetch the value once, and complete the Observable right after, and with it unsubscribe all the subscriptions, you can do the following :

this.productService.get(id).valueChanges().pipe(
  take(1)
).subscribe(p => this.product = p)
Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149