Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular rxjs takeUntilDestroyed

Just need some clarification on documentation of takeUntilDestroyed operator, so reading this doc: https://angular.io/api/core/rxjs-interop/takeUntilDestroyed , I dont see any words that I should use takeUntilDestroyed without params only in "injection" context (I dont really know what does this means). So basicly "Otherwise, the current DestroyRef is injected." so I can use it every where in component, directive, service, etc.

So question is this documentation is not fully describe how injection happens or it is problem with me?

(Please dont put any link explaining how this operator works, I know exactly how it works and checked source code, question is about documentation understanding)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The injection context is explained in this doc. Basically, it’s a runtine context where a current injector is set and Angular is able to use for dependency injection.

takeUntilDestroyed requires an DestroyREf to schedule the observable completion. this can be done 2 ways:

  • rely in DI to get it, that the default behaviour and uses inject(DestroyRef). inject requires of course an injection context
  • Pass DestroyRef as argument, so no injection context is required.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading