我正在使用 Angular-Material 中的 md-datepicker 指令,但是我想输入日期,而不仅仅是从日期选择器中选择它。我找到了以下示例代码:
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);
};
});
我现在的问题是在 MEANJS yeoman 生成器应用程序中的何处使用 .config 部分。我找不到任何东西。到目前为止有人这样做过吗?
如果您在加载 md-datepicker 文件并将其加载到 MEAN.JS 中时遇到问题,请查看这个答案.
但是,如果您已经将文件正确加载到应用程序中,并且只想访问应用程序的配置块,则可以通过访问位于/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
在配置块中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)