当我改变数据库的值时,它不需要刷新就会反映在我的页面中。所以我想停止实时数据反射。
constructor(public af: AngularFireDatabase,
public route: ActivatedRoute) {
this.addemployee = af.list('/employees');
this.employee = af.object('/employees');
}
getEmployees() {
this.employees = this.af.list('/employees') as FirebaseListObservable<any[]>;
return this.employees;
}发布于 2017-08-10 21:29:31
解决方案:添加take(1),使代码行为this.employees = this.af.list('/employees').take(1) as FirebaseListObservable<any[]>;
如果我没理解错的话。你不想要实时更新,只想要数据一次。
您可能正在使用:https://firebase.google.com/docs/reference/js/firebase.database.Reference#on,这是为您提供数据更新的工具。
ref.on('value', function(dataSnapshot) {
// ...
});如果只需要一次数据,可以使用:https://firebase.google.com/docs/reference/js/firebase.database.Reference#once
// Basic usage of .once() to read the data located at ref.
ref.once('value')
.then(function(dataSnapshot) {
// handle read data.
});更新:添加了非常简单的JavaScript示例,request from comment。
var ref = firebase.database().ref('database/path/to/something');
ref.once('value')
.then(function(dataSnapshot) {
// handle read data.
let data = dataSnapshot.val();
// data is { "name": "Ada", "age": 36 }
// data.name === "Ada"
// data.age === 36
});https://stackoverflow.com/questions/45615057
复制相似问题