简体   繁体   English

AngularUI - 视图和值中的UI Bootstrap Datepicker日期不同

[英]AngularUI - UI Bootstrap Datepicker date on view and in the value are different

I have a problem with Uib Datepicker . 我有Uib Datepicker的问题。 I have to dynamically change date format. 我必须动态更改日期格式。 for example: 例如:

  <input type="text" class="form-control" ng-model="field.value" ng-value="field.value" name="{{field.name}}" uib-datepicker-popup="dateFormat" // I could be yy-MM and other is-open="openedStart" datepicker-options="dateOptions" show-button-bar="false" show-weeks="false" ng-click="openedStart = !openedStart" /> 

In the calendar view it's shown good, as I want, for example "16-05" as it was inserted "yy-MM" , but to the backend goes value: "2016-05-02T21:00:00.000Z" which is stores in the ng-value . 在日历视图中,它显示为好,如我所愿,例如"16-05"因为它插入了"yy-MM" ,但是后端value: "2016-05-02T21:00:00.000Z"这是以ng-value存储。

How to fix it and send to the backend the same value as in the view? 如何修复它并向后端发送与视图中相同的值?

The datepicker directive requires the ng-model value to be a JavaScript date object (like the Angular input - date directive). datepicker指令要求ng-model值为JavaScript日期对象(如Angular input-date指令)。 If you need to send the date as "yy-MM" to a service, you can format it using the Angular date filter . 如果您需要将日期作为“yy-MM”发送到服务,则可以使用Angular日期过滤器对其进行格式化。 The date filter will also work if your displaying the ng-model value to another part of your view. 如果您将ng-model值显示到视图的另一部分,则日期过滤器也将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM