【问题标题】:How to replace deprecated uib-datepicker-popup?如何替换已弃用的 uib-datepicker-popup?
【发布时间】:2016-03-29 13:03:30
【问题描述】:

由于我将我的项目更新为"angular-bootstrap": "~1.2.4",我在控制台中收到了警告:

uib-datepicker settings via uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead

uib-datepicker-popup 由日期格式或日期格式数组填充:

  • uib-datepicker-popup="dd-MMMM-yyyy" 就我而言

所以在angular bootstrap documentation 中仍然显示deprecated 处理这种情况的方式。

有人知道如何迁移到新版本吗?

【问题讨论】:

    标签: angularjs datepicker angular-bootstrap


    【解决方案1】:

    他们没有弃用“uib-datepicker-popup”属性,警告与“日期选择器设置”部分datepicker docs 中列出的所有属性有关。您必须通过属性“datepicker-options”提供这些值。 不知道为什么,但是“弹出设置”部分中的那些没有发出警告。

    在我的情况下,我有

    JS

    $scope.datepicker.format = 'shortDate';
    $scope.datepicker.options = {
        formatYear: 'yy',
        startingDay: 1
    };
    

    HTML

    <input type="text" class="form-control" 
         ng-model="ngModel"
         uib-datepicker-popup="{{ datepicker.format }}"
         datepicker-options="datepicker.options"
    
         datepicker-append-to-body="true" 
         is-open="datepicker.opened"               
         show-button-bar="false"
         close-text="Close"
    
         min-date="minDate"
         max-date="maxDate"
         custom-class="getCustomClass"
         show-weeks="false"
         />
    

    它变成了

    JS

    $scope.datepicker.format = 'shortDate';
    $scope.datepicker.options = {
        formatYear: 'yy',
        startingDay: 1,
        minDate: minDate,
        maxDate: maxDate,
        showWeeks: false,
        customClass: getCustomClass
    };
    

    HTML

    <input type="text" class="form-control" 
         ng-model="ngModel"
         uib-datepicker-popup="{{ datepicker.format }}"
         datepicker-options="datepicker.options"
    
         datepicker-append-to-body="true" 
         is-open="datepicker.opened"               
         show-button-bar="false"
         close-text="Close" 
         />
    


    更新

    plunker reproduction

    【讨论】:

    • uib-datepicker-popup="dd-MMMM-yyyy" 给了我一个警告,没有别的
    • 我遇到了同样的问题。如果您删除值 "dd-MMMM-yyyy" 并且只保留 uib-datepicker-popup,您是否检查过警告是否仍然触发?
    • 在 plunker 上添加了示例,尝试注释/取消注释最后一个 datepicker 以查看它是警告的来源,其中 uib-datepicker-popup 没有任何值,而第一个 datepicker 不触发任何警告.
    • @McGiogen 在日期选项中使用 formatYear: 'yy', 有什么用?
    • 正如您在datepicker documentation 中看到的,formatYear: 'yy' 将年份范围的格式从 yyyy(例如:1990-1995)更改为 yy(例如:90-95)。在这个答案中,它只是一个配置示例。
    【解决方案2】:

    【讨论】:

    • 谢谢我没有提醒这个文档。但是它说:Change: datepicker-popup for uib-datepicker-popup.。但是uib-datepicker-popup 正是要贬值的……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 2017-04-17
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    相关资源
    最近更新 更多