Skip to content

The query Error won't go. #10

Description

@MadaZZ

import { Injectable } from '@angular/core';
//import { AngularFireDatabase } from 'angularfire2/database';
import { AngularFireDatabase,FirebaseListObservable } from 'angularfire2/database-deprecated';
import { AngularFireAuth } from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import { AuthService } from '../services/auth.service';
import * as firebase from 'firebase/app';
import { ChatMessage } from '../models/chat-message.model'

@Injectable()
export class ChatService {
user: any;
chatMessages: FirebaseListObservable<ChatMessage[]>;
chatMessage: ChatMessage;
userName: Observable;

constructor( private db: AngularFireDatabase, private afAuth: AngularFireAuth){
this.afAuth.authState.subscribe(auth=>{
//We have set user to auth if it is not undefined or null
if(auth !== undefined && auth !== null){
this.user=auth;
}
});
}

//Function to send message
sendMessage(msg:string){
var timestamp= this.getTimeStamp();
var email= this.user.email;
this.chatMessages=this.getMessages();
this.chatMessages.push({
message: msg,
timeSent: timestamp,
userName: this.userName,
email1: email
});
}

//Function to get timeStamp
getTimeStamp(){
const now = new Date();
const date = now.toLocaleDateString();
const time = now.toLocaleTimeString();
return(date+ ' ' + time);
}

//this function gets message from firebase.
getMessages(): FirebaseListObservable<ChatMessage[]> {
// query to create our message feed binding
return this.db.list('messages', {
query: {
limitToLast: 25,
orderByKey: true
}
});
}
}

Above is my complete chatService code (still corrections required in getTimeStamp() )
But the error in the query won't go. Please help me out asap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions