I'm relatively new to Firebase and Angular2. I'm currently working on creating a chat app that integrates Firebase with Angular2 based on tutorials I've been following. Specifically, I've been using this tutorial to build the chat app. While I have successfully implemented the basic chat functionality, I'm now looking to add a toast notification whenever a new chat message is sent or received. However, I'm having trouble locating the code that allows me to listen for this event.
Does anyone know where I can find this code snippet?
The Angular component code snippet looks like the following:
import { Component } from '@angular/core';
import { AngularFire, AuthProviders, AuthMethods, FirebaseListObservable } from 'angularfire2';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
items: FirebaseListObservable<any>;
name: any;
msgVal: string = '';
constructor(public af: AngularFire) {
this.items = af.database.list('/messages', {
query: {
limitToLast: 5
}
});
this.af.auth.subscribe(auth => {
if(auth) {
this.name = auth;
}
});
}
login() {
this.af.auth.login({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup,
});
}
chatSend(theirMessage: string) {
this.items.push({ message: theirMessage, name: this.name.facebook.displayName});
this.msgVal = '';
}
}
Here is the corresponding HTML markup:
<div class="row columns">
<button (click)="login()" *ngIf="!name">Login With Facebook</button>
<input type="text" id="message" *ngIf="name" placeholder="Chat here..." (keyup.enter)="chatSend($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>