如何全局配置Angular UI引导指令

时间:2015-11-03 10:57:41

标签: angularjs angular-ui angular-ui-bootstrap

如何在全局范围内使用uibDatepickerConfig配置bootstrap datepicker?文档只是说明如下:

  

所有设置都可以作为uib-datepicker中的属性提供,也可以通过uibDatepickerConfig进行全局配置。

source code中,它们被定义为常量

.constant('uibDatepickerConfig', {
    formatDay: 'dd',
    formatMonth: 'MMMM',
    formatYear: 'yyyy',
    formatDayHeader: 'EEE',
    formatDayTitle: 'MMMM yyyy',
    formatMonthTitle: 'yyyy',
    datepickerMode: 'day',
    minMode: 'day',
    maxMode: 'year',
    showWeeks: true,
    startingDay: 0,
    yearRange: 20,
    minDate: null,
    maxDate: null,
    shortcutPropagation: false
})

this post已经讨论了完全相同的问题,但解决方案似乎过时

1 个答案:

答案 0 :(得分:9)

//where app is the module that depends on 'ui.bootstrap'
// probably your main app module

//for DatePicker options
app.config(['uibDatepickerConfig', function (uibDatepickerConfig) {
    uibDatepickerConfig.showWeeks = false;
}]);

//for DatePickerPopup options
app.config(['uibDatepickerPopupConfig', function (uibDatepickerPopupConfig) {
    uibDatepickerPopupConfig.closeText= 'Close';
    uibDatepickerPopupConfig.placement = 'auto bottom';
}]);