【问题标题】:How to diable previous dates in angular-io-datepicker如何在 angular-ui-datepicker 中禁用以前的日期
【发布时间】:2017-06-27 13:29:38
【问题描述】:

我对 angular 4 了解不多,谁能告诉我如何在 angular-io-datepicker 中禁用以前的日期。

【问题讨论】:

  • 可以使用primeng的datepicker吗?更好

标签: angular datepicker angular-ui-datepicker


【解决方案1】:

******************抱歉,这不是正确的日期选择器插件。但我留下它以防万一你想切换

如果这是您正在使用的用户界面,请查看最小日期按钮。

http://angular-ui.github.io/bootstrap/#!#%2Fdatepicker

html:

<button type="button" class="btn btn-sm btn-default" ng-click="toggleMin()" uib-tooltip="After today restriction">Min date</button>

angularjs:

$scope.toggleMin = function() {
    $scope.options.minDate = $scope.options.minDate ? null : new Date();
  };

【讨论】:

  • 对不起,我提交了它,然后意识到我在谈论错误的日期选择器
【解决方案2】:

您应该使用min 输入来执行此操作。
只需将其添加到您放置mdDatepicker 指令的input 标记上,然后将min 绑定到将有效日期与无效日期分开的日期。
在此示例中,我使用 new Date() 来禁用当前日期之前的所有日期。

@Component({
  selector: 'app-root',
  template: `<input [mdDatepicker]="datePicker" [min]="minDate">
             <button [mdDatepickerToggle]="datePicker"></button>
             <md-datepicker #datePicker></md-datepicker>`,
})
export class AppComponent {
  minDate = new Date();
}

【讨论】:

  • 抱歉,我以为您使用的是datePicker of material2。我查看了 API 参考和您正在使用的组件的源代码。我找不到做你想做的事的方法。
猜你喜欢
  • 1970-01-01
  • 2021-03-06
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多