Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the post date upon submit?

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?

like image 251
wexorchid Avatar asked Nov 28 '25 21:11

wexorchid


1 Answers

You can use firebase.database.ServerValue.TIMESTAMP see https://firebase.google.com/docs/database/web/offline-capabilities#server-timestamps

like image 62
Mathew Berg Avatar answered Nov 30 '25 12:11

Mathew Berg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!