【问题标题】:How to configure Angular UI bootstrap directives globally如何全局配置 Angular UI 引导指令
【发布时间】:2015-11-03 10:57:41
【问题描述】:

如何在全局范围内使用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 已经讨论了完全相同的问题,但解决方案似乎过时

【问题讨论】:

  • 你试过那个解决方案了吗?
  • @PetrAveryanov 是的,我有。它不工作(不再),因为他们没有使用 providers。也许这在去年发生了变化。
  • plnkr.co/edit/NpS0QtA88ZBzxBQMXfIE?p=preview(仅来自角度引导页面的示例)与该解决方案中的工作方式相同(只是在名称中添加了“uib”)

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


【解决方案1】:
//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';
}]);

【讨论】:

  • 未定义 uibDatepickerConfig。您缺少该变量的注入。
  • angular 能够注入它,只要你不缩小/丑化。
  • 不知道,在我这边由于某些原因它给了我一个错误
  • 所以这就是它不起作用的原因。我被要求在 uib 前面加上前缀。非常感谢!弹出窗口的工作方式相同:uibDatepickerPopupConfig
猜你喜欢
  • 1970-01-01
  • 2013-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多