AngularJS 1.3 - Datepicker initial format is incorrect

前端 未结 2 2157
暗喜
暗喜 2021-02-12 11:25

I started using AngularJS 1.3 yesterday and one problem I have found is that the initial date in the Datepicker is not in the defined format. The format of the date is correct <

2条回答
  •  面向向阳花
    2021-02-12 11:44

    Not sure exactly what changed in 1.3, but there is a bug report for this.

    Here's a drop-in directive for the initial value that fixes the problem until the bug is fixed. And here is a demo Plunker.

    angular.module('myApp').directive('datepickerPopup', function (dateFilter, datepickerPopupConfig) {
        return {
            restrict: 'A',
            priority: 1,
            require: 'ngModel',
            link: function(scope, element, attr, ngModel) {
                var dateFormat = attr.datepickerPopup || datepickerPopupConfig.datepickerPopup;
                ngModel.$formatters.push(function (value) {
                    return dateFilter(value, dateFormat);
                });
            }
        };
    });
    

提交回复
热议问题