AngularJS得到格式化NG-型号日期 [英] AngularJS get formatted date in ng-model
本文介绍了AngularJS得到格式化NG-型号日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下文字输入型号值时间戳填充:
I have following text input filled by model value in timestamp:
<input type="datetime" ng-model="workerDetail.dateOfBirth" class="form-control" id="date_of_birth" />
它显示在输入作为给定的时间戳值。
It displays value in input as given timestamp.
我想转换值,它是可见的输入格式的日期(YYYY / MM / DD),但在模型应该始终作为时间戳。
I would like to convert value which is visible in input into formatted date (YYYY/MM/DD), but in model should be always as timestamp.
我试图通过这种方式来做到这一点:
I tried to do it by this way:
{{workerDetail.dateOfBirth | date:'MMM'}}
但是,如果没有运气。
But without luck.
感谢您的任何建议。
推荐答案
您可以尝试一个过滤器
HTML
<input type="datetime" ng-model="mydateOfBirth" class="form-control" id="date_of_birth" />
控制器JS
$scope.$watch('mydateOfBirth', function (newValue) {
$scope.workerDetail.dateOfBirth = $filter('date')(newValue, 'yyyy/MM/dd');
});
$scope.$watch('workerDetail.dateOfBirth', function (newValue) {
$scope.mydateOfBirth = $filter('date')(newValue, 'yyyy/MM/dd');
});
这篇关于AngularJS得到格式化NG-型号日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文