33 lines
964 B
TypeScript
33 lines
964 B
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {AngularFireDatabase, SnapshotAction} from '@angular/fire/compat/database';
|
|
import {Observable} from 'rxjs';
|
|
import {Body} from './body';
|
|
|
|
@Component({
|
|
selector: 'app-bodies',
|
|
templateUrl: './bodies.component.html',
|
|
styleUrls: ['./bodies.component.scss']
|
|
})
|
|
export class BodiesComponent implements OnInit {
|
|
public bodies: Observable<SnapshotAction<Body>[]> = new Observable<SnapshotAction<Body>[]>();
|
|
|
|
constructor(private database: AngularFireDatabase) { }
|
|
|
|
ngOnInit(): void {
|
|
const bodyRef = this.database.list<Body>('bodies')
|
|
this.bodies = bodyRef.snapshotChanges();
|
|
}
|
|
|
|
public addBody(newBody: string): void {
|
|
const bodyRef = this.database.list<Body>('bodies');
|
|
bodyRef.push({name: newBody});
|
|
}
|
|
|
|
public deleteBody(bodyKey: string|null): void {
|
|
const bodyRef = this.database.list<Body>('bodies');
|
|
if (bodyKey != null) {
|
|
bodyRef.remove(bodyKey);
|
|
}
|
|
}
|
|
}
|