Format md-datepicker in angular inconsistent

3

I have a md-datepicker defined with Angular 1.X:

<md-datepicker ng-model="query.filter.mindate"></md-datepicker>

How can I define the format of the date of this component?

I have already read some answers about it (like this ) where they propose to use the mdDateLocaleProvider.formatDate and parseDate and It does not work for me.

I have also tried to put it in the following way:

<md-datepicker ng-model="query.filter.mindate">{{date : 'D/M/YYYY'}}</md-datepicker>

And this one:

<md-datepicker ng-model="query.filter.mindate">{{myFecha date : 'D/M/YYYY'}}</md-datepicker>

But this does not work either, the validation occurs as if I expected M/D/YYYY and I do not see how to modify it.

Is there any way to put some tag in the same HTML so that it validates with the format you want?

    
asked by Miquel Coll 09.02.2017 в 15:42
source

1 answer

1

Thanks to the comment of x4mp73r that was going to this question from the original OS that has fixed the problem for me.

What I had to do is put this in my config:

$mdDateLocaleProvider.formatDate = function (date) {
    return date ? moment(date).format('D/M/YYYY') : '';
};

$mdDateLocaleProvider.parseDate = function (dateString) {
    var m = moment(dateString, 'D/M/YYYY', true);
    return m.isValid() ? m.toDate() : new Date(NaN);
};

And the validation already works as it should and lets make the post requests without problems.

    
answered by 09.02.2017 / 17:11
source