Getting this error in my Ionic 3 project while try to retrieve firebase data and display in a page. I am followed this code but this not working, it still get an error. How can I fixed this error: “Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed”
I am followed this code:
import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database'; @Component({ selector: 'page-chat', templateUrl: 'chat.html', }) export class ChatPage { username: string = ''; message: string = ''; _chatSubscription; messages: object[] = []; constructor(public db: AngularFireDatabase, public navCtrl: NavController, public navParams: NavParams) { this.username = this.navParams.get('username'); this._chatSubscription = this.db.list('/chat').valueChanges().subscribe( data => { this.messages = data; }); } }
You have to import rxjs-compat in your ionic project. First install it apply this line in command
npm i rxjs@^6.0 rxjs-compat
Now import rxjs-compat in your .ts file
import { Observable } from ‘rxjs-compat’;
And apply this code to retrive and display data from firebase database.
this._chatSubscription = this.db.list("/chat).valueChanges().subscribe( data => { this.messages = data; });
Question and answer is powered by AnsPress.io