Instead of “manually” updating a record’s created_at and modified_at timestamps
inside multiple controller methods, we can more conveniently override the
$firebaseArray.$add() methods which will
automatically handle these timestamp properties for every record.
For this, you will need to have the AngularFire library installed.
Then just decorate AngularFire’s
factories like so:
The above code will add a
created_at property to all new records before
creating and appending them to a collection with
This decorator will update the
modified_at property before calling
It’s important to note that Firebase provides a canonical timestamp value via
Firebase.ServerValue.TIMESTAMP, so make sure to always use it instead of the
browser’s local timestamp.