-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanet.component.ts
More file actions
45 lines (39 loc) · 1.07 KB
/
Copy pathplanet.component.ts
File metadata and controls
45 lines (39 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Observable, Subject, take, takeUntil } from 'rxjs';
import { Planet } from '../model';
import { PlanetRepositoryService } from '../planet-repository.service';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-planet',
standalone: true,
imports: [
CommonModule
],
templateUrl: './planet.component.html',
styleUrl: './planet.component.scss'
})
export class PlanetComponent implements OnInit, OnDestroy {
private readonly destroy$ = new Subject<void>();
protected planets$: Observable<Planet[]> | null = null;
constructor(private planetRepository: PlanetRepositoryService) {
}
ngOnDestroy(): void {
this.destroy$.next();
}
ngOnInit(): void {
this.planets$ = this.planetRepository.getAllPlanets();
}
addPlanet() {
const planet: Planet = {
name: 'Earth',
avgTemp: '65',
habitable: 'yes'
}
this.planetRepository.addPlanet(planet)
.pipe(
take(1),
takeUntil(this.destroy$)
)
.subscribe()
}
}