Reputation: 2299
Below is my firebase database screenshot:
Below is the code in the "app.component":
import { AngularFireDatabase, FirebaseListObservable } from "angularfire2/database-deprecated";
import { AngularFireAuth } from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
@Component ....
items: FirebaseListObservable<any[]>;
constructor(public af: AngularFireDatabase) {
this.items = af.list('/projects', {
query: {
limitToLast: 10
}
});
console.log(this.items);
}
but I'm not getting the data. Could anyone help me out on this?
I've completed the angularfire2 setup and able to write the data to the real time database. It's the issue with getting the data from db.
Upvotes: 0
Views: 3116
Reputation: 2246
You need to call a subscribe method on the list. As such:
this.items = af.list('/projects').valueChanges().subscribe(items => {
console.log(items);
}));
I see that u are using a the database-deprecated
package. The code should be as such:
this.firebaseList = af.list('/projects'); // This is of type FirebaseListObservable
this.items = this.firebaseList.subscribe(items => {
console.log(items);
})); // This is of type subscription.
this.firebaseList.push({...data}); // Now you can push.
Upvotes: 2