Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误类型错误:将循环结构转换为JSON-->;从具有构造函数的对象开始';FirebaseAppImpl';火基角_Javascript_Angular_Firebase_Google Cloud Firestore_Angularfire2 - Fatal编程技术网

Javascript 错误类型错误:将循环结构转换为JSON-->;从具有构造函数的对象开始';FirebaseAppImpl';火基角

Javascript 错误类型错误:将循环结构转换为JSON-->;从具有构造函数的对象开始';FirebaseAppImpl';火基角,javascript,angular,firebase,google-cloud-firestore,angularfire2,Javascript,Angular,Firebase,Google Cloud Firestore,Angularfire2,当我试图从一个可观察对象获取数据时,我从控制台得到了这个错误 我的代码如下所示 import { Injectable } from '@angular/core'; import { AngularFirestore } from '@angular/fire/firestore'; @Injectable({ providedIn: 'root' }) export class ViewRepor

当我试图从一个可观察对象获取数据时,我从控制台得到了这个错误

我的代码如下所示

     import { Injectable } from '@angular/core';
        import { AngularFirestore } from '@angular/fire/firestore';
        @Injectable({
          providedIn: 'root'
        })
        export class ViewReportService {
          constructor(private firestore: AngularFirestore) { }
          getReport = (myDocument) => 
            this.firestore.collection("report").doc(myDocument).get()
        }
英语服务-Service.ts

     import { Injectable } from '@angular/core';
        import { AngularFirestore } from '@angular/fire/firestore';
        @Injectable({
          providedIn: 'root'
        })
        export class ViewReportService {
          constructor(private firestore: AngularFirestore) { }
          getReport = (myDocument) => 
            this.firestore.collection("report").doc(myDocument).get()
        }
组件ts

  import { Component, OnInit } from '@angular/core';
    import { ViewReportService } from '../shared/view-report.service';
    import { Observable } from 'rxjs';
    @Component({
      selector: 'app-view-report',
      templateUrl: './view-report.component.html',
      styleUrls: ['./view-report.component.scss']
    })
    export class ViewReportComponent implements OnInit {
      document= [];
      document$ : Observable<any>;
      constructor(private service: ViewReportService) { }
      ngOnInit(){
        let documentID = "----"
        //Get the Data from the view-report service
        this.document$ = this.service.getReport(documentID);
      }
    }
从'@angular/core'导入{Component,OnInit};
从“../shared/view report.service”导入{ViewReportService};
从“rxjs”导入{Observable};
@组成部分({
选择器:“应用程序视图报告”,
templateUrl:'./view report.component.html',
样式URL:['./查看报表.component.scss']
})
导出类ViewReportComponent实现OnInit{
文件=[];
文件$:可见;
构造函数(私有服务:ViewReportService){}
恩戈尼尼特(){
让documentID=“-----”
//从视图报告服务获取数据
this.document$=this.service.getReport(documentID);
}
}
在我的HTML视图上

 <table *ngIf="document$ | async as document">
        <pre>{{document.name}}</pre> 

{{document.name}

听起来像是有一个循环对象结构,然后不能存储在数据库中。请记住:Firestore文档只能包含JSON数据,并且并非所有JavaScript对象都是有效的JSON。例如:JavaScript对象可能包含在JSON中无效的函数定义


将JavaScript对象转换为JSON的最简单方法是
JSON.parse(JSON.stringify(object))
。您需要在将对象写入数据库的位置执行此操作。

Hey jevie。你看到我下面的答案了吗?你有没有把这个和那个一起工作过?如果我的答案有用,请单击向上投票按钮(▲) 如果它回答了您的问题,请单击复选标记(✓) 接受它。这样别人就会知道你已经得到了(足够的)帮助。也请参见