AngularJS:Unix时间戳、Ng模型和HTML日期输入
使用“date”类型的输入时,从json提要获取Unix时间戳并使用AngularJS和ng模型正确格式化的最佳方法是什么 使用此标记:AngularJS:Unix时间戳、Ng模型和HTML日期输入,angularjs,date,model,timestamp,Angularjs,Date,Model,Timestamp,使用“date”类型的输入时,从json提要获取Unix时间戳并使用AngularJS和ng模型正确格式化的最佳方法是什么 使用此标记: <input type="date" ng-model="item.date" /> 不工作,因为输入需要特定格式的日期或字符串,而不是时间戳。您可以为所有输入创建指令,例如: item.date = new Date(timestamp) angular.directive("input", function () { retur
<input type="date" ng-model="item.date" />
不工作,因为输入需要特定格式的日期或字符串,而不是时间戳。您可以为所有输入创建指令,例如:
item.date = new Date(timestamp)
angular.directive("input", function () {
return {
require: 'ngModel',
link: function (scope, elem, attr, modelCtrl) {
if (attr['type'] === 'date') {
modelCtrl.$formatters.push(function (modelValue) {
if (modelValue) {
return new Date(modelValue);
} else {
return null;
}
});
}
}
};
});
你应该充实你的答案。