Setting another Date forma in MEANjs with md-datepicker

前端 未结 1 1236
执笔经年
执笔经年 2021-01-23 15:24

I am using the md-datepicker directive from angular-material, however i would like to typ in the date, not only choose it from the datepicker. I found the following example code

相关标签:
1条回答
  • 2021-01-23 15:48

    If you're having trouble loading the md-datepicker files and get it to be loaded into MEAN.JS check out this answer.

    However if you are already correctly loading your files into your app and you just want to access the config block of the app you can do so by accessing the file located in /modules/core/client/app/init.js, and in this code block just add the logic needed:

    // Setting HTML5 Location Mode
      angular
        .module(app.applicationModuleName)
        .config(bootstrapConfig);
    
      function bootstrapConfig($compileProvider, $locationProvider, $httpProvider, $mdDateLocaleProvider) {
        $locationProvider.html5Mode(true).hashPrefix('!');
    
        $httpProvider.interceptors.push('authInterceptor');
    
        // Disable debug data for production environment
        // @link https://docs.angularjs.org/guide/production
        $compileProvider.debugInfoEnabled(app.applicationEnvironment !== 'production');
    
        // md-datepicker configuration
        $mdDateLocaleProvider.formatDate = function(date) {
            return date ? moment(date).format('DD.MM.YYYY') : '';
        };
        $mdDateLocaleProvider.parseDate = function(dateString) {
            var m = moment(dateString, 'DD.MM.YYYY', true);
            return m.isValid() ? m.toDate() : new Date(NaN);
        };
    }
    
    bootstrapConfig.$inject = ['$compileProvider', '$locationProvider', '$httpProvider', '$mdDateLocaleProvider'];
    

    Don't forget to inject $mdDateLocaleProvider in the config block.

    0 讨论(0)
提交回复
热议问题