Allow Moment.js dates in bootstrap-ui datepicker

前端 未结 2 565
后悔当初
后悔当初 2021-02-13 19:18

I\'m trying to use Bootstrap UI\'s DatePicker with Moment.js dates.

It is possible if I convert my model value from Moment.js date to standard Date prior to

2条回答
  •  -上瘾入骨i
    2021-02-13 20:08

    I haven't tested this but you might be able to do this.

    Create a customer filter that that returns the normal date...something like the below

    angular.module('phonecatFilters', []).filter('momentToDate', function() {
        return function(momentDate) {
            if (moment.isMoment(momentDate)) {
                return momentDate.toDate();
            }else { return momentDate }
        };
    });
    

    Then where you declare you directive ng-model="yourmomentdate | momentToDate"

提交回复
热议问题