简体   繁体   English

使用日期选择器更改角度输入的日期格式

[英]Change date format of angular input with date picker

I'm very new to angular and have a label with a textbox that shows a date picker. 我对angular非常陌生,并且有一个带有显示日期选择器的文本框的标签。 I want the format of the input field to show the date in a format that are read from database table. 我希望输入字段的格式以从数据库表读取的格式显示日期。

<label for='example'>Date</label>
<input type='text' class='form-control' date-Picker id="from" required ng-model="data.myDate" ng-model-options="{ getterSetter: true }">

How can I change the format of the input text box? 如何更改输入文本框的格式?

What you need is to filter the date according to the format that you want to show You can find information about the date and how you can format it here 您需要根据要显示的格式过滤日期。您可以在此处找到有关日期以及如何设置日期格式的信息。

1) in your controller you can do: 1)在您的控制器中,您可以执行以下操作:

 $scope.data.myDate =  $filter('date')(new Date(), 'dd.MM.yyyy', '');

2) in your view: 2)在您看来:

{{ data.myDate | format: 'dd.MM.yyy' }}

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

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