Fra*_*sco 5 firebase angularfire2 angular
使用angulafire它可以在将记录pushid保存到数据库之前检索它:
myModelDto.key = dbRef.push().key;
// Add the myModelDto to the relative colletion
Run Code Online (Sandbox Code Playgroud)
这很方便,因为我可以将firebase密钥存储为我的模型的属性.
现在,angularfire2这似乎不可能以干净/简单的方式:
constructor(private angFire: AngularFire) {
this.placeRef$ = angFire.database.list('/places');
}
insertPlace = (place: IPlace): firebase.Thenable<IPlace> => {
return this.placeRef$.push(place)
.then(item => {
place.id = item.key;
this.placeRef$.update(item.key, place)
});
Run Code Online (Sandbox Code Playgroud)
因此,我想知道我是否以错误的方式接近firebase(为了方便起见,希望将一个关键属性绑定到我的模型上),或者是否有更好的方法将pushid添加到新添加的记录中.
看看这个关于 angularfire2 问题的答案
https://github.com/angular/angularfire2/issues/199
卡纳夫甘写道:
const pushId = this.afDb.createPushId();
const item = { ...item, id: pushId };
this.afDb.list('items').set(item.id, item);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
349 次 |
| 最近记录: |