How To Input A Time Into Firebase With Angularfire?
I'd like a user to be able to submit a time into the firebase database by selecting a time from the input box. I know how to have the user enter text into firebase based on the fi
Solution 1:
A few things are going on here:
- An input of type
text
(the default type for an input) will return a string - An input of type
time
will return a Date object - Firebase stores JSON data
- There is no JSON data type for Date objects
So you will have to convert the time you get into a supported type, before passing it to Firebase.
$scope.addMessage = function() {
$scope.messages.$add({
text: $scope.newMessageText.toString()
});
};
Note that storing a date as a string is great if you want to only display the date. But if you want to also manipulate it (e.g. filter based on the date), you will probably want to store it as a timestamp:
$scope.addMessage = function() {
$scope.messages.$add({
text: $scope.newMessageText.toString(),
timestamp: $scope.newMessageText.getTime(),
});
};
Post a Comment for "How To Input A Time Into Firebase With Angularfire?"