Angular bootstrap datepicker date format does not format ng-model value

后端 未结 13 1356
借酒劲吻你
借酒劲吻你 2020-12-01 04:24

I am using bootstrap date-picker in my angular application. However when I select a date from that date-picker underlying ng-model that I have bind gets updated I want that

13条回答
  •  Happy的楠姐
    2020-12-01 04:46

    You may use formatters after picking value inside your datepicker directive. For example

    angular.module('foo').directive('bar', function() {
        return {
            require: '?ngModel',
            link: function(scope, elem, attrs, ctrl) {
                if (!ctrl) return;
    
                ctrl.$formatters.push(function(value) {
                    if (value) {
                        // format and return date here
                    }
    
                    return undefined;
                });
            }
        };
    });
    

    LINK.

提交回复
热议问题