Skip to content

Commit

Permalink
fix(): unsubscribe fixes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
inpercima committed Dec 27, 2024
1 parent 0c9f407 commit 1ce51b5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions frontend/src/app/shared/lunch/lunch.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, OnInit, inject } from '@angular/core';
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MatCardModule } from '@angular/material/card';
import { MatDividerModule } from '@angular/material/divider';
import { MatProgressBarModule } from '@angular/material/progress-bar';
Expand All @@ -16,6 +17,8 @@ export class LunchComponent implements OnInit {
route = inject(ActivatedRoute);
private lunchService = inject(LunchService);

private destroyRef = inject(DestroyRef);

lunch: Lunch[] = [];
path: string;

Expand All @@ -28,9 +31,12 @@ export class LunchComponent implements OnInit {
}

ngOnInit(): void {
this.lunchService.get(this.path).subscribe((lunch) => {
this.lunch = lunch;
this.loaded = true;
});
this.lunchService
.get(this.path)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((lunch) => {
this.lunch = lunch;
this.loaded = true;
});
}
}

0 comments on commit 1ce51b5

Please sign in to comment.