How can I automatically push a date as property into Firebase? Here's the function for adding a book with alertcontrol method.
addBook() {
console.log("add book button click-ed");
let alert = this.alertCtrl.create({
title: 'Book Title and Author',
message: 'Book Cover',
inputs: [
{
name: 'title',
placeholder: 'Book Title'
},
{
name: 'author',
placeholder: 'Author of the Book'
},
{
name: 'cover',
placeholder: 'Cover URL'
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
console.log('Cancel click-ed')
}
},
{
text: 'Save Book',
handler: data => {
this.books.push({
title: data.title,
author: data.author,
cover: data.cover,
})
}
}
]
})
alert.present();
}
I've set the prop input for title, author, and covers. It works fine. The addBook() function binds to a button that has that method. But how should I go if I want to get the post date and add it to Firebase as props 'date' when user clicked the button?
You can use firebase.database.ServerValue.TIMESTAMP see https://firebase.google.com/docs/database/web/offline-capabilities#server-timestamps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With