2016-09-19 112 views
1

我现在用的MD-日期选择指令从角的材料,但是我想在日期TYP,不仅从日期选择器选择它MEANjs另一个日期备考。我发现下面的示例代码:设置在与MD-日期选择器

 angular.module('MyApp') 
      .controller('AppCtrl', function($scope) { 
      $scope.myDate = new Date(); 

      $scope.minDate = new Date(
      $scope.myDate.getFullYear()-1, 
      $scope.myDate.getMonth(), 
      $scope.myDate.getDate()); 

      $scope.maxDate = new Date(
      $scope.myDate.getFullYear()+1, 
      $scope.myDate.getMonth(), 
      $scope.myDate.getDate()); }) 

      .config(function($mdDateLocaleProvider) { 
      $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); 
      }; 
     }); 

我现在的问题是在哪里使用的.config部分在MEANJS自耕农发电机的应用。我找不到任何东西。有人这样做了吗?

+0

到目前为止,我把它在我的控制器等,并安装了片刻,注入但不知何故,它不能被发现。 – d8ta

回答

1

如果您无法加载MD-日期选择文件并把它装载到MEAN.JS退房this answer

然而,如果你已经正确地加载你的文件到您的应用程序,你只是要访问的应用程序的配置块,你可以通过访问位于/modules/core/client/app/init.js文件这样做,并且在这个代码块只需添加所需的逻辑:

// 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']; 

不要忘记在配置块中注入$mdDateLocaleProvider

+0

谢谢,我认为这正是我需要的。如果这是有帮助的,请检查一下,并且不要显示。再次 – d8ta

+0

谢谢,我花了一段时间来回到这个问题,因为我们有一个发射和日期格式是有点不上个月的优先事项。但是通过你的代码,我可以让选择器使用我们想要的格式。一个问题是在Mean.js应用程序上安装moment.js。这帮助了很多:Howto:如何添加Moment.js到MEAN.js项目(http://zklinger2000.github.io/blog/2016/03/22/add-momentjs-to-meanjs)。谢谢! – d8ta

相关问题