【发布时间】:2019-03-03 03:12:39
【问题描述】:
我这样上传到数据库:
我要上传的对象:
export class Data {
$key: string;
name: string;
address: string;
address2: string;
pscode: string;
ccode: string;
name2: string;
trucks: Trucks;
trailers: Trailers;
email: string;
phone: string;
city: string;
country: string;
}
**Upload service :**
getItem: Observable<Data[]>;
key: string;
busines = {} as Data;
createItemAuth() {
this.afAuth.authState.subscribe(auth => {
this.afDatabase.list(`users/${this.auth.userId}/company`).push(this.busines)
});
}
//this not works :
getUploads() {
this.getItem = this.afDatabase.list(`profile/${this.auth.userId}/company/`).snapshotChanges().map((actions) => {
return actions.map((a) => {
const data = a.payload.val();
const $key = a.payload.key;
const $ref = a.payload.ref;
return { $key, ...data, $ref };
});
});
return this.getItem;
}
在getUploads() this.getItem 我明白了:
键入'{ $ref:参考; $key:字符串; }[]' 不可分配给类型 '数据[]'。 键入'{ $ref:参考; $key:字符串; }' 不可分配给类型“数据”。 类型'{ $ref:参考; 中缺少属性'名称' $key:字符串; }'。
这有什么问题?
【问题讨论】:
-
你使用的是 rxjs 6 吗?
-
"rxjs": "^6.1.0",
-
同样的错误,可能不存在问题
-
现在只缺少属性键而不是名称
标签: typescript firebase firebase-realtime-database angular6