1
I am creating an application where underneath the content of the page I have the option of the user to make a comment. I’m using firebase to register and login and I’ve even been able to record the message in the database, but only she, needed to put the name of the user or username, and the date the comment was made.
My html is like this:
<ion-content #content id="content">
<ion-card *ngFor="let message of messages">
<ion-card-header>
{{message.nome}}
</ion-card-header>
<ion-card-content>
{{message.mensagem}}
</ion-card-content>
<ion-footer>
<ion-toolbar>
<ion-input placeholder="Comente algo..." [(ngModel)]="message"></ion-input>
<ion-buttons end>
<button ion-button icon-right (click)="sendMessage()">
Enviar
<ion-icon name="send"></ion-icon>
</button>
</ion-buttons>
my ts is like this:
export class Cap1SegObsPage {
@ViewChild("content") content: any;
username: string
message: string = ""
messages = [];
constructor(public navCtrl: NavController) {
this.getMessages();
}
getMessages(){
var messagesRef = firebase.database().ref().child("mensSegObsCap1");
messagesRef.on("value", (snap) => {
var data = snap.val();
this.messages = [];
for(var key in data){
this.messages.push(data[key]);
}
this.scrollToBottom();
});
}
scrollToBottom(){
var contentEnd = document.getElementById("content-end").offsetTop;
this.content.scrollTo(0, contentEnd, 300);
}
sendMessage(){
var messagesRef = firebase.database().ref().child("mensSegObsCap1");
messagesRef.push({mensagem: this.message, nome: this.username});
this.message = "";
}
}
And how do I do that? It’s my first app and I don’t have much sense of Ionic
– Reinaldo Souza