Проблема при получении данных из Firebase с использованием ionic + angularfire2 - PullRequest
0 голосов
/ 28 мая 2018

Я следую инструкциям по созданию приложения чата с использованием Ionic и AngularFire2.

Однако у меня возникает эта ошибка, когда я пытаюсь получить данные из базы данных Firebase.

TypeError: Object(...) is not a function
at SwitchMapSubscriber.project (http://localhost:8100/build/vendor.js:74005:76)
at SwitchMapSubscriber._next (http://localhost:8100/build/vendor.js:62295:27)
at SwitchMapSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
at RefCountSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)
at RefCountSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
at Subject.next (http://localhost:8100/build/vendor.js:23237:25)
at ConnectableSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)
at ConnectableSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
at Notification.observe (http://localhost:8100/build/vendor.js:51893:50)
at AsyncAction.DelaySubscriber.dispatch (http://localhost:8100/build/vendor.js:76316:40)

Мой код Chat.TS

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireDatabase} from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';

/**
 * Generated class for the ChatPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-chat',
  templateUrl: 'chat.html',
})
export class ChatPage {

  username: string = '';
  message : string = '';
  //messages : object[] = [];
  items: Observable<any[]>;

  constructor(public db: AngularFireDatabase , public navCtrl: NavController, public navParams: NavParams) {
    console.log(this.navParams);
    this.username = this.navParams.get('username');
    this.items = db.list('chat').valueChanges();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ChatPage');
  }

  sendMessage(){
    this.db.list('/chat').push({
      username:this.username,
      message:this.message
    });
  }
}

Мой код Chat.HTML

<ion-header>

  <ion-navbar>
    <ion-title>Chat</ion-title>
  </ion-navbar>

</ion-header>



<ion-content padding>

  <ul>
     <li *ngFor="let item of items | async">
        {{ item | json }}
     </li>
   </ul>

</ion-content>


<ion-footer>
  <ion-toolbar>
    <ion-input type="text" [(ngModel)]="message"></ion-input>
    <button ion-button icon-only (click)="sendMessage()"><ion-icon name="send"></ion-icon>
    </button>
  </ion-toolbar>
</ion-footer>

Я пробовал много разных способов сделать это, и я все еще получаю ту же ошибку объекта.Кто-нибудь есть идеи, что вызывает эту ошибку?Спасибо за вашу помощь.

...