【问题标题】:Not able to set default Angular uib-datepicker date to null / empty无法将默认 Angular uib-datepicker 日期设置为空/空
【发布时间】:2018-02-08 09:18:20
【问题描述】:

我使用的 Angular-bootstrap 版本是 0.14.2

问题:虽然我将 ng-model 设置为 "" 或 null,但它设置为 currentDate。我希望它是空的。无法弄清楚是什么问题。

<input class="form-control" type="text"
       datepicker-append-to-body="true" uib-datepicker-popup="{{dateFormat}}"
       ng-model="businessJet.ExpirationDate"
       ng-change="info.updateRampFee(businessJet);"
       ng-click="businessJet.popupOpened = true"
       is-open="businessJet.popupOpened"
       ng-disabled="!businessJet.IsApplicable" />

【问题讨论】:

    标签: javascript angularjs datepicker angular-bootstrap


    【解决方案1】:

    将模型设置为 null 会将文本设置为空白。

    http://plnkr.co/edit/KjkZi814j36jAbEr3x3y

    $scope.dateFormat = 'dd-MMMM-yyyy';
    
    $scope.businessJet = {
        ExpirationDate:null,
        updateRampFee: function(dateObj) {
            console.log('date changed',dateObj)
        },
        popupOpened : false,
        IsApplicable : true
    };
    
    <input class="form-control" 
          type="text"
          datepicker-append-to-body="true" 
          uib-datepicker-popup="{{dateFormat}}"
          ng-model="businessJet.ExpirationDate"
          ng-change="businessJet.updateRampFee(businessJet);"
          ng-click="businessJet.popupOpened = true"
          is-open="businessJet.popupOpened"
          ng-disabled="!businessJet.IsApplicable" />
    

    【讨论】:

    • 我忘了说,businessJet 是一个数组对象。正如您所做的那样,我将所有 businessJet 对象 ExpirationDate 设置为 null。它没有在视图上设置为空。它适用于 Plunker。不在我的申请中。奇怪的行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多