2016-09-22 72 views
0

我有一个表单提交数据。我在该表单中有一个日期字段。一切工作正常。但是,当我尝试检索数据更新包括日期。我收到错误“ngModel:datefmt”。 我试过在数据库YY-mm-dd和dd-mm-yy中转换日期格式。 我已经尝试在JavaScript中将日期格式转换为yy-mm-dd和dd-mm-yy。 我正在使用input type =“date”。角度js在更新日期时出错

+0

请提供一些工作或非工作的代码示例,以便我们可以帮助您 – nikjohn

回答

0

你有日期字符串,因此你得到你需要将其转换为Date对象的错误,

$scope.dateField = new Date(date_string); 

我会建议使用指令该输入元素来使用它。

<input convert-date type="date" ng-model="dateField"> 

app.directive('convertDate', function(){ 
return { 
    restrict : 'A', 
    scope : {ngModel : '='}, 
    link: function (scope) { 
     if (scope.ngModel) 
     { 
     scope.ngModel = new Date(scope.ngModel); 
     } 
    } 
} 
}); 
+0

您是对的!而不是使用指令我用toString()来转换数据库日期和它为我工作。谢谢 !! –