3

我有一个关于在angularfire插入对象公司的FireStore问题微胶囊对象OK:(但是这是一个很好的做法?)将在公司的FireStore和货物的做法

[person.component.ts] 
     this.db.collection("person").add({ 
       name: this.person.$nome, 
       age: this.person.$email 
      }) 
    ... 

但如果我尝试:

[person.component.ts] 
     this.db.collection("person").add({ 
        Person: this.person 
//or this this.person 
        }) 

我得到这个错误在浏览器控制台:

功能DocumentReference.set()调用无效数据。不支持的字段值:一个自定义的Person对象(在该领域人找到) 在新FirestoreError(error.js:149) 在

+1

你设法解决这个问题?我在保存自定义对象时遇到了同样的问题,尽管Google认为它应该是可行的 - https://firebase.google.com/docs/firestore/manage-data/add-data –

+0

我继续使用{key:values }方式: onsubmit(){ this.db.collection(“user”).add({name:this.form.get('name').value, email:this.form.getemail:。 .. –

回答

2

公司的FireStore只接受嵌入在文档内的JavaScript对象,如果它是“纯”对象这意味着在使用TypeScript进行编码时不能使用自定义对象。

更改您的代码:

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