我正在尝试获取用户输入的手动输入。但是当我将日期输入为dd/MM/yyyy
时,它总是为NULL。当我给dd/MM/yyyy HH:mm
时它会起作用。更多关于我的onChange()函数不会调用。
Angular JS代码:
(function() {
'use strict';
/**
* My Controller
*/
angular.module('test').controller('MyController', MyController);
// The $inject property is an array of service names to inject.
MyController.$inject = ['GenericGetService', 'GenericPostService', '$routeParams', '$location', '$rootScope'];
function MyController(GenericGetService, GenericPostService, $routeParams, $location, $rootScope) {
var myController = this;
myController.openCalendar = openCalendar;
myController.isOpen = false;
myController.onChange = onChange;
myController.myDate = null;
function openCalendar(e) {
e.preventDefault();
e.stopPropagation();
myController.isOpen = true;
};
function onChange() {
console.log(myController.myDate);
}
}
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<p class="input-group">
<input type="text" id="myDate" initialPicker="date" ng-change="onChange()" class="form-control" datetime-picker="dd/MM/yyyy HH:mm" defaultTime="00:00:00" data-ng-model="myController.myDate" is-open="myController.isOpen" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="myDate.openCalendar($event)"><i class="fa fa-calendar"></i></button>
</span>
</p>
以下是Demo Code
的代码如何解决此问题?如何使用dd / MM / yyyy和dd / MM / yyyy HH:mm格式?
注意:使用Javascript我可以获得值
var data = document.getElementById('myDate').value;
myController.myDate = new Date(data);
答案 0 :(得分:0)
我看到你当前的图书馆已经支持它了
只需在html中添加alt-input-formats="['MM/dd/yyyy HH:mm', 'MM/dd/yyyy']"
即可
或者你可以在这里尝试一个实例
https://plnkr.co/edit/QUgR6r?p=preview