Angularjs 在firestore和商品实践中插入封装对象

Angularjs 在firestore和商品实践中插入封装对象,angularjs,firebase-realtime-database,google-cloud-firestore,angularfire5,Angularjs,Firebase Realtime Database,Google Cloud Firestore,Angularfire5,我想在angularfire中的firestore中插入对象: 我的对象Person.ts name: String age: Number //--constructor-- //--getters and setters-- 如果我这样做,请插入ok:(但这是一种良好的做法吗?) 但如果我尝试: [person.component.ts] this.db.collection("person").add({ Person:

我想在angularfire中的firestore中插入对象:

我的对象Person.ts

name: String
age: Number
//--constructor--
//--getters and setters--
如果我这样做,请插入ok:(但这是一种良好的做法吗?)

但如果我尝试:

    [person.component.ts]
         this.db.collection("person").add({
                     Person: this.person
//or this this.person
                  })
我在浏览器控制台中遇到此错误:

使用无效数据调用函数DocumentReference.set()。不支持的字段值:自定义人员对象(在“人员”字段中找到) 在新建FirestoreError时出错(error.js:149)

Firestore中,如果JavaScript对象是“纯”对象,则仅接受嵌入在文档中的JavaScript对象,这意味着您在使用TypeScript编码时不能使用自定义对象

将代码更改为:

this.db.collection("person").add(Object.assign({}, this.person)); 

你解决了这个问题吗?我在保存自定义对象时也遇到同样的问题,尽管Google说这应该是可能的-我继续使用{key:values}way:onsubmit(){this.db.collection(“user”).add({name:this.form.get('name')。value,email:this.form.getemail:。。。
this.db.collection("person").add(Object.assign({}, this.person));