Skip to content

Commit

Permalink
Merge pull request #6315 from qmonmert/angularDestroyRef
Browse files Browse the repository at this point in the history
Angular 16: DestroyRef Provider
  • Loading branch information
pascalgrimaud authored May 19, 2023
2 parents c6d6667 + ea02cf9 commit 2ae8b48
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { Component, inject, OnDestroy, OnInit } from '@angular/core';
import { Component, DestroyRef, inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Subject, takeUntil } from 'rxjs';
import { AccountService } from '../auth/account.service';
Expand All @@ -17,7 +17,7 @@ import { MatCardModule } from '@angular/material/card';
standalone: true,
styleUrls: ['./login.component.css'],
})
export default class LoginComponent implements OnInit, OnDestroy {
export default class LoginComponent implements OnInit {
private readonly destroy$ = new Subject<void>();
account: Account | null = null;
Expand All @@ -33,6 +33,11 @@ export default class LoginComponent implements OnInit, OnDestroy {
username: ['', [Validators.required]],
password: ['', [Validators.required]],
});
const destroyRef = inject(DestroyRef);
destroyRef.onDestroy(() => {
this.destroy$.next();
this.destroy$.complete();
});
}

ngOnInit(): void {
Expand All @@ -42,11 +47,6 @@ export default class LoginComponent implements OnInit, OnDestroy {
.subscribe(account => (this.account = account));
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}

login(): void {
this.loginService
.login({
Expand Down

0 comments on commit 2ae8b48

Please sign in to comment.