Finished bodies
This commit is contained in:
parent
0044bebe2f
commit
9f14ad8e5a
|
@ -7,8 +7,10 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let body of bodies | async">
|
<tr *ngFor="let body of bodies | async">
|
||||||
<td>{{body.name}}</td>
|
<td>{{body.payload.val()?.name}}</td>
|
||||||
<td><span class="bi bi-x-lg"></span></td>
|
<td><button class="btn btn-outline-danger" type="button" (click)="deleteBody(body.key)">
|
||||||
|
<span class="bi bi-trash"></span>
|
||||||
|
</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
td {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {AngularFireDatabase} from '@angular/fire/compat/database';
|
import {AngularFireDatabase, SnapshotAction} from '@angular/fire/compat/database';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {Body} from './body';
|
import {Body} from './body';
|
||||||
|
|
||||||
|
@ -9,17 +9,24 @@ import {Body} from './body';
|
||||||
styleUrls: ['./bodies.component.scss']
|
styleUrls: ['./bodies.component.scss']
|
||||||
})
|
})
|
||||||
export class BodiesComponent implements OnInit {
|
export class BodiesComponent implements OnInit {
|
||||||
public bodies: Observable<Body[]> = new Observable<Body[]>();
|
public bodies: Observable<SnapshotAction<Body>[]> = new Observable<SnapshotAction<Body>[]>();
|
||||||
|
|
||||||
constructor(private database: AngularFireDatabase) { }
|
constructor(private database: AngularFireDatabase) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const bodyRef = this.database.list<Body>('bodies')
|
const bodyRef = this.database.list<Body>('bodies')
|
||||||
this.bodies = bodyRef.valueChanges();
|
this.bodies = bodyRef.snapshotChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public addBody(newBody: string): void {
|
public addBody(newBody: string): void {
|
||||||
const bodyRef = this.database.list<Body>('bodies');
|
const bodyRef = this.database.list<Body>('bodies');
|
||||||
bodyRef.push({name: newBody});
|
bodyRef.push({name: newBody});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteBody(bodyKey: string|null): void {
|
||||||
|
const bodyRef = this.database.list<Body>('bodies');
|
||||||
|
if (bodyKey != null) {
|
||||||
|
bodyRef.remove(bodyKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue