Unsubscribe on ngOnDestroy hook
Advantages:
- simplicity,
- can unsubscribe individually.
Disadvantages:
- boilerplate code,
- a potential problem with the initial value (not null safety),
- need to manually unsubscribe.
Unsubscribe on ngOnDestroy hook with subscriptions container
Advantages:
- simplicity,
- null safety,
- need to unsubscribe always only once.
Disadvantages:
- boilerplate code,
- need to manually unsubscribe.
Unsubscribe with async pipe
Advantages:
- no need to implement OnInit and OnDestroy interfaces, async pipe does it automatically,
- independent of change detection strategy if data from a stream are used within a template.
Disadvantages:
- less performance (async is not a pure pipe) with comparison to subscribe in component logic.
Complete stream with takeUnitl operator
Advantages:
- simplicity,
- null safety,
- calling next on destroy$ causes complete on all streams.
Disadvantages:
- need to manually unsubscribe.
Unsubscribe/Complete with destroyable local service
Thanks to destroyable local service you can move unsubscribe logic outside the component.
Advantages:
- automatically unsubscribe, no need to implement OnInit and OnDestroy interfaces,
- unsubscribe logic is handled in one place,
- the single-responsibility principle is preserved,
- BONUS: you can handle unsubscribe and takeUntil pattern in one place
Disadvantages:
- the component has an additional provider.