Closed jblancas-git closed 7 years ago
Hi, not @jadjoubran but i think this should work haven't test it 😆
export function DatepickerConfig($mdDateLocaleProvider, moment){
'ngInject';
this.$mdDateLocaleProvider = $mdDateLocaleProvider;
this.moment= moment;
// Example uses moment.js to parse and format dates.
this.$mdDateLocaleProvider.parseDate(dateString)=> {
var m = thi.moment(dateString, 'L', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
this.$mdDateLocaleProvider.formatDate(date)=> {
var m = this.moment(date);
return m.isValid() ? m.format('DD/MM/YYYY') : '';
};
}
Thank you so much @flick36 for answering!
I also never tried the above code
but what you're seeing in the terminal is just eslint
complaining that moment
was never defined.. You can alter your eslint configuration to define moment
as a global..
Or you could add this conditional comment:
/* global moment:false */
at the top of the file to silence this warning from eslint
Thank you so much @flick36 & @jadjoubran for your help!
I did some things that you recommended me and my code was working correctly.
The code looks like this: ---File: .eslintrc---
"globals": {
"angular": true,
"module": true,
"moment": true,
"inject": true
}
---Config File: datepicker.config.js ---
export function DatepickerConfig($mdDateLocaleProvider){
'ngInject';
// Example uses moment.js to parse and format dates.
$mdDateLocaleProvider.parseDate = function(dateString) {
var m = moment(dateString, 'L', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
$mdDateLocaleProvider.formatDate = function(date) {
var m = moment(date);
return m.isValid() ? m.format('DD/MM/YYYY') : '';
};
}
*The format date is working
Thank you!!
Sounds great 😄
Hi, Jad!, I'm trying to use the angular-moment in my laravel-angular project version 3.3.0 ...
[ ] bug report
[ ] feature request
[X] support request
[ ] other (Please specify)
Provide information & explanation I need to config the $mdDateLocaleProvider in order to customize the DatePicker control and be able to format the date just like example of the angular-material web page.
What I Did: 1.- Using bower I installed the angular-moment package. 2.- I did "artisan ng:config datepicke" in order to make config files according to example: (https://material.angularjs.org/latest/api/service/$mdDateLocaleProvider)
-- datepicker.config.js--
3.- I ran Gulp for compile.
result:
Thank you very much for you help us!