0

So, I have a component like

class DialogLoginComponent {
    constructor(
        private dialogRef: MatDialogRef<DialogLoginComponent>,
        private store: Store<Auth.State>
    ) {}

    onDoSomething(): void {
        this.dialogRef.close(); 

        this.dialogRef.afterClosed().subscribe(() =>
            this.store.dispatch(new RegistrationActions.OpenRegistrationDialog())
        );
    }
}

The question is, once the component gets destroyed, does the subscription get to still live or is Angular / RxJS smart enough to unsubscribe it automatically?

nhaa123
  • 9,570
  • 11
  • 42
  • 63

1 Answers1

0

No, the subscription will still live unless you:
- unsubscribe it by unsubscribe() somewhere, in ngDestroy maybe? but this not recommended, see https://medium.com/@benlesh/rxjs-dont-unsubscribe-6753ed4fda87.
- use first() or take(1) so you will be sure that the subscription will complete and not stay live after getting the first result

sarea
  • 215
  • 1
  • 13