Мне не удается получить сообщение из базы данных, но я не могу отправлять сообщения, и никаких ошибок не происходит.Я искал и пробовал все, но не смог найти проблему в моем коде.
МОЙ КОМПОНЕНТ APP
import {Component, OnInit} from '@angular/core';
import { AngularFireList, AngularFireDatabase } from
'angularfire2/database';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
items: AngularFireList<any>;
name: any;
msgVal = '';
constructor(public af: AngularFireDatabase, public afAuth:
AngularFireAuth) {
this.items = this.af.list('/messages' , ref =>
ref.limitToLast(5));
}
ngOnInit() {
this.name = this.afAuth.authState;
console.log(this.name);
}
login() {
const provider = new firebase.auth.FacebookAuthProvider();
return this.afAuth.auth.signInWithPopup(provider);
}
logout() {
return this.afAuth.auth.signOut();
}
Send(desc: string) {
this.items.push({ message: desc, name: this.name.toString()});
this.msgVal = '';
}
}
МОЙ КОМПОНЕНТ HTML
<div class="row columns">
<button (click)="login()" *ngIf="!name">Login With
Facebook</button>
<button (click)="logout()" *ngIf="name">Logout</button>
<input type="text" id="message" *ngIf="name" placeholder="Chat
here..." (keyup.enter)="Send($event.target.value)"
[(ngModel)]="msgVal" />
<div class="chat-container" *ngFor="let item of (items |async)">
<a href="#">{{item.name}}</a>
<p>{{item.message}}</p>
</div>
</div>
МОЙ МОДУЛЬ ПРИЛОЖЕНИЯ
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFireModule } from 'angularfire2';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {FormsModule} from '@angular/forms';
export const firebaseConfig = {
apiKey: 'AIzaSyA1VrfxnvWrde7-KIHovQAyeNDCTVyxFJ8',
authDomain: 'appchat-2a8ec.firebaseapp.com',
databaseURL: 'https://appchat-2a8ec.firebaseio.com',
projectId: 'appchat-2a8ec',
storageBucket: 'appchat-2a8ec.appspot.com',
messagingSenderId: '269198800174',
appId: '1:269198800174:web:18bc3da705673518'
};
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
AngularFireModule.initializeApp(firebaseConfig),
AngularFireDatabaseModule,
AngularFireAuthModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Я хочу получать сообщения из firebase, чтобы их можно было отображать на html-странице.Нет ошибки, я не знаю, почему это происходит.Пожалуйста, помогите мне найти ошибку.