import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase,AngularFireList } from 'angularfire2/database';
import { exception, time } from 'console';
import { Observable } from 'rxjs';
import {formatDate} from '@angular/common';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
//--< Daten >--
title = 'dailycheck';
notes_Firebase_Data :AngularFireList<any>;
notes_angular :Observable<any[]>;
constructor( private afDb:AngularFireDatabase ) {
}
ngOnInit()
{
//----< ngOnInit() >----
//* get table in firebase for create read update delete
this.notes_Firebase_Data= this.afDb.list('Notes');
//* get android observable ngfor
this.notes_angular=this.notes_Firebase_Data.valueChanges();
//----</ ngOnInit() >----
}
add_node_in_firebase()
{
//----< add_node_in_firebase() >----
//*creates a new node with details in firebase
this.notes_Firebase_Data.push({
title:'note added by angular.push()',
details: 'this note ist created with angularfirelist<any>. To list it in ngFor, you need an observable<any[]>',
datetime: new Date().toString()
});
//----</ add_node_in_firebase() >----
}
update_set_firebase()
{
//----< update_set_firebase() >----
//*find and replace a node in Firebase
//*if no match, then create new
//*set : replaces complete node
//*update : replaces only matching key values
this.notes_Firebase_Data.update('2012/02',{
title:'this note is set by angularfirelist.update()',
details: 'this note ist created with angularfirelist<any>. To list it in ngFor, you need an observable<any[]>',
datetime: formatDate( Date.now(),'yyyy-MM-dd hh:nn','en-US')
});
//----</ update_set_firebase() >----
}
remove_in_firebase()
{
//----< remove_in_firebase() >----
//*removes node,
//*result is promise...
this.notes_Firebase_Data.remove('2012/02')
.then(x=>console.log("Success removed"))
.catch(error =>console.log("Error",error));
//----</ remove_in_firebase() >----
}
}
|