Angular Firebase einzelne Node ausgeben
Notizbuch
- Notiz1
- Beschreibung: "erst mal was überlegen, dann notiern.notierne"
- Titel: "Wie erstellt man eine Notiz"
1)
Code für Ausgabe in der .html Seite
In der app.component.html
Mit | Async und ?.Element
Bedeutung von ? Fragezeichen hinter (firebase-node | async)?.subnote
Wichtig: das ? bedeutet, dass auf den Asynchronen Wert solange gewartet wird, bis er ausgeben werden kann.
{{ (notiz1 |async )?.Titel }} |
App.component.html Code
<h1>{{title}}</h1> <ul> <li *ngFor="let item of aufgaben | async"> {{ item }} </li> </ul> {{ (notiz1 |async )?.Titel }} |
2)
Code für Ausgabe in der .html Seite
Hier wird die Variable als Observable deklariert
public notiz1 :Observable<any>;
|
Und mit .list(node).valueschanges() abgeholt
this.notiz1=this.afDb.object("/Notizbuch/Notiz1").valueChanges();
|
App.component.ts Code
import { Component } from '@angular/core'; import { AngularFireDatabase,AngularFireList } from 'angularfire2/database'; import { Observable } from 'rxjs';
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { //--< Daten >-- title = 'dailycheck'; public aufgaben : Observable<any>; public notiz1 :Observable<any>; constructor( private afDb:AngularFireDatabase ) { }
ngOnInit() { this.aufgaben = this.afDb.list('Aufgaben').valueChanges(); this.notiz1=this.afDb.object("/Notizbuch/Notiz1").valueChanges(); } }
|