无法为ui-date angularjs指定日期

时间:2016-02-01 09:12:29

标签: angularjs angular-ui-datepicker

我想将字符串日期分配给ui-date

我的观点

 <input ng-switch-when="datePicker" type="text" ui-date-format ui-date class="form-control" ng-model="field.value" />

和我的日期字符串 &#34; 12 /二千零十五​​分之十二&#34;

但是我收到了这个错误&#34;错误:ng-Model值必须是Date对象 - 目前它是一个字符串 - 使用ui-date-format将其转换为字符串&#34;

请有人帮助我,谢谢

1 个答案:

答案 0 :(得分:1)

尝试在控制器中执行(错误:ng-Model值必须是Date对象

$scope.field.value = new Date($scope.field.value);

或者将带有日期掩码的date-format attribute添加到输入标记

ui-date-format="DD/MM/YYYY"