我有一个DATE字段(开始日期),用户可以输入任何日期的屏幕
I have a screen with a DATE field (Start Date) where the user can enter any date
<label class="item item-input"> <span class="input-label">Start Date</span> <input type="date" ng-model="currentItem.OpenDate"> </label>我在保存按钮的点击事件中添加了以下内容:
I added the following to the Save button's click event
console.log("Normal date " + $scope.currentItem.OpenDate);控制台显示以下日期
The console shows the following date
Normal date Fri May 01 2015 00:00:00 GMT-0400 (Eastern Daylight Time)以下是推送事件
Here's the push event
$scope.data.accounts.push({ 'AccountName': $scope.currentItem.AccountName, 'StartBalance': $scope.currentItem.StartBalance, 'OpenDate': $scope.currentItem.OpenDate, 'AccountType': $scope.currentItem.AccountType });然而,日期 $ scope.currentItem.OpenDate 没有保存到Firebase,其余数据正常保存。我错过了什么?
HOWEVER, the date $scope.currentItem.OpenDate is not getting saved to Firebase, the rest of the data is saving properly. What am I missing?
推荐答案你不幸的是没有包含初始化 OpenDate 属性。但看起来您正尝试将JavaScript Date 对象写入Firebase。 Firebase文档指定它支持以下类型:
You unfortunately didn't include the code that initializes the OpenDate property. But it looks like you're trying to write a JavaScript Date object into Firebase. The Firebase documentation specifies that it supports these types:
对象,数组,字符串,数字,布尔值或 null
为了存储 Date 的值,您必须将其转换为受支持的类型。例如
In order to store the Date's value, you will have to convert it to a supported type. E.g.
$scope.data.accounts.push({ 'AccountName': $scope.currentItem.AccountName, 'StartBalance': $scope.currentItem.StartBalance, 'OpenDate': $scope.currentItem.OpenDate.toString(), 'AccountType': $scope.currentItem.AccountType });或者:
Or alternatively:
'OpenDate': $scope.currentItem.OpenDate.getTime(),更多推荐
如何使用AngularFire在Firebase中保存DATE字段
发布评论