wesdoyle / base-chat

A simple chat application built using Angular and Firebase
52 stars 52 forks source link

I can't get the data from firebase in feed component. #12

Open isitme opened 6 years ago

isitme commented 6 years ago

I'm currently using angular 6

i did all the same in feed.component.ts

import { Component, OnInit, OnChanges } from '@angular/core'; import { ChatService } from '../services/chat.service'; import { Observable } from 'rxjs'; import { chatMessegeModel } from '../models/chat-message.model'; import { FirebaseListObservable } from 'angularfire2/database';

@Component({ selector: 'app-feed', templateUrl: './feed.component.html', styleUrls: ['./feed.component.css'] }) export class FeedComponent implements OnInit, OnChanges { feed: FirebaseListObservable<chatMessegeModel[]>;

constructor(private chat: ChatService) { }

ngOnInit() { this.feed = this.chat.getMessages(); }

ngOnChanges() { this.feed = this.chat.getMessages(); }

} and the Template:

*ngFor="let message of feed | async" <app-message [chatMessage]=message >

But the console show me this Error:

ERROR TypeError: rxjs_operators__WEBPACK_IMPORTED_MODULE_4__.switchMap.call(...).subscribe is not a function at FirebaseListObservable._subscribe (firebase_list_factory.js:75) at FirebaseListObservable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:42) at FirebaseListObservable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:28) at ObservableStrategy.push../node_modules/@angular/common/fesm5/common.js.ObservableStrategy.createSubscription (common.js:4498) at AsyncPipe.push../node_modules/@angular/common/fesm5/common.js.AsyncPipe._subscribe (common.js:4578) at AsyncPipe.push../node_modules/@angular/common/fesm5/common.js.AsyncPipe.transform (common.js:4559) at Object.eval [as updateDirectives] (FeedComponent.html:1) at Object.debugUpdateDirectives [as updateDirectives] (core.js:11061) at checkAndUpdateView (core.js:10458) at callViewAction (core.js:10699

kranthi1996 commented 5 years ago

this.chatservice.getMessages().valueChanges().subscribe(data => { this.messagesData = data; })

al-freezy commented 2 years ago

this.chatservice.getMessages().valueChanges().subscribe(data => { this.messagesData = data; })

And how do you write it in the html template?