以下是“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);
}
但我没有收到数据。有谁可以帮我解决这个问题?
我已完成angularfire2设置并能够将数据写入实时数据库。这是从db获取数据的问题。
答案 0 :(得分:2)
您需要在列表上调用订阅方法。就这样:
this.items = af.list('/projects').valueChanges().subscribe(items => {
console.log(items);
}));
我看到你正在使用database-deprecated
包。代码应该是这样的:
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.