正在解析 ui.bootstrap.datepicker 个对象
Parsing ui.bootstrap.datepicker object
我为 ui.bootstrap.datepicker 写了一个指令。 (http://angular-ui.github.io/bootstrap/) 它运行良好,但一旦选择了日期,它可能不会将日期对象解析回控件。选择日期后未应用日期格式。
未应用日期格式。
应用日期格式(我希望它是这样的)
当我调试时,我可以看到两个不同的对象。
- "Thu Aug 28 2014 08:00:00 GMT+0800 (W. Australia Standard Time)"
- "2014-08-28T00:00:00"
有什么想法吗?
app.directive('reusablePicker', function ($compile) {
var template =
' <div class="input-group">'+
' <input type="text" class="form-control datepicker" datepicker-popup="dd-MMMM-yyyy" ng-model="pickerDate" is-open="dateOpened" ng-focus="dateOpen($event)" close-text="Close" ng-disabled="disabled" />' +
' <div class="input-group-addon" ng-click="dateOpen($event)" ' +
' <a href="#"><i class="linecons-calendar"></i></a>'+
' </div>' +
' </div>';
var linker = function (scope, element, attrs, ngModelCtrl) {
scope.disabled = attrs.ngDisabled;
ngModelCtrl.$render = function () {
scope.pickerDate = ngModelCtrl.$viewValue;
};
scope.$watch('pickerDate', function () {
ngModelCtrl.$setViewValue(scope.pickerDate);
});
element.html(template).show();
$compile(element.contents())(scope);
};
return {
require: 'ngModel',
link: linker,
replace: true,
restrict: 'EA',
scope: {},
controller: ['$scope', function ($scope) {
$scope.dateOpen = function ($event) {
if ($scope.disabled !== "true") {
$event.preventDefault();
$event.stopPropagation();
$scope.dateOpened = true;
}
};
}]
};
});
ngModelCtrl.$parsers.push(function (modelValue) {
var date = new Date(modelValue).toISOString();
return date;
});
我为 ui.bootstrap.datepicker 写了一个指令。 (http://angular-ui.github.io/bootstrap/) 它运行良好,但一旦选择了日期,它可能不会将日期对象解析回控件。选择日期后未应用日期格式。
未应用日期格式。
应用日期格式(我希望它是这样的)
当我调试时,我可以看到两个不同的对象。
- "Thu Aug 28 2014 08:00:00 GMT+0800 (W. Australia Standard Time)"
- "2014-08-28T00:00:00"
有什么想法吗?
app.directive('reusablePicker', function ($compile) {
var template =
' <div class="input-group">'+
' <input type="text" class="form-control datepicker" datepicker-popup="dd-MMMM-yyyy" ng-model="pickerDate" is-open="dateOpened" ng-focus="dateOpen($event)" close-text="Close" ng-disabled="disabled" />' +
' <div class="input-group-addon" ng-click="dateOpen($event)" ' +
' <a href="#"><i class="linecons-calendar"></i></a>'+
' </div>' +
' </div>';
var linker = function (scope, element, attrs, ngModelCtrl) {
scope.disabled = attrs.ngDisabled;
ngModelCtrl.$render = function () {
scope.pickerDate = ngModelCtrl.$viewValue;
};
scope.$watch('pickerDate', function () {
ngModelCtrl.$setViewValue(scope.pickerDate);
});
element.html(template).show();
$compile(element.contents())(scope);
};
return {
require: 'ngModel',
link: linker,
replace: true,
restrict: 'EA',
scope: {},
controller: ['$scope', function ($scope) {
$scope.dateOpen = function ($event) {
if ($scope.disabled !== "true") {
$event.preventDefault();
$event.stopPropagation();
$scope.dateOpened = true;
}
};
}]
};
});
ngModelCtrl.$parsers.push(function (modelValue) {
var date = new Date(modelValue).toISOString();
return date;
});