Sec*_*one 2 javascript datetime timestamp angularjs angular-ngmodel
我试图渲染一个表示时间戳的<input type="datetime-local>
字段ng-model
:
<input type="datetime-local" ng-model="object.value">
Run Code Online (Sandbox Code Playgroud)
同
$scope.object.value = 1433109600000;
Run Code Online (Sandbox Code Playgroud)
控制台显示[ngModel:datefmt]
错误.
如何正确绑定$scope.object.value
到输入字段?(时间戳来自nestest对象中的Web服务)
一些Plnkr:http://plnkr.co/edit/TGpKVNF1tv0b1h6JPBT8?p = preview
kar*_*una 10
它必须是日期对象:
$scope.object = {
name: 'Demo',
value: new Date(1433109600000)
}
Run Code Online (Sandbox Code Playgroud)
或者创建一个指令:
app.directive('bindTimestamp', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
ngModel.$formatters.push(function (value) {
return new Date(value);
});
}
};
});
Run Code Online (Sandbox Code Playgroud)