javascript - 如何从角度的开始月份禁用或只读日期选择器月份?
问题描述
我想在开始日期后 2 个月禁用或只读开始。但是,如果我选择这两个月以外的任何月份,那么在那一天计算 2 个月。
我想禁用或只读,或者用户不选择从开始月份开始的 2 个直接月份。
当我选择九月然后将开始日期计算到所选日期。
组件.ts
@Component({
selector: 'app-tax-time-period',
templateUrl: './tax-time-period.component.html',
styleUrls: ['./tax-time-period.component.scss'],
})
export class TaxTimePeriodComponent implements OnInit {
endDateDisable = true;
defaultPickerValue: Date | null = null;
@ViewChild('endDatePicker') endDatePicker!: NzDatePickerComponent;
startDate!: Date;
disabledEndDate = (endDate: Date): boolean => {
if (!endDate || !this.startDate) {
return false;
}
return endDate.getTime() < this.startDate.getTime() ;
}
}
html
<nz-form-item>
<nz-form-label>Start Date</nz-form-label>
<nz-form-control>
{{ startDate ? (startDate | date: "YYYY-MM-dd") : "N/A" }}
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzRequired> End Date</nz-form-label>
<nz-form-control
[nzSpan]="5"
nzHasFeedback
[nzErrorTip]="endDateErrorTpl"
>
<nz-month-picker
#endDatePicker
[nzDisabledDate]="disabledEndDate"
nzFormat="yyyy-MM-dd"
formControlName="endDate"
nzPlaceHolder="End"
(nzOnOpenChange)="handleEndOpenChange($event)"
nzMode="month"
[nzDisabled]="endDateDisable"
[nzDefaultPickerValue]="defaultPickerValue"
></nz-month-picker>
解决方案
@Component({
selector: 'app-tax-time-period',
templateUrl: './tax-time-period.component.html',
styleUrls: ['./tax-time-period.component.scss'],
})
export class TaxTimePeriodComponent implements OnInit {
endDateDisable = true;
defaultPickerValue: Date | null = null;
@ViewChild('endDatePicker') endDatePicker!: NzDatePickerComponent;
startDate!: Date;
disabledEndDate = (endDate: Date): boolean => {
if (!endDate || !this.startDate) {
return false;
}
if (endDate.getMonth() === 0) {
return true;
}
if (endDate.getMonth() === 1) {
return true;
}
if (endDate.getMonth() === 3) {
return true;
}
if (endDate.getMonth() === 4) {
return true;
}
if (endDate.getMonth() === 6) {
return true;
}
if (endDate.getMonth() === 7) {
return true;
}
if (endDate.getMonth() === 9) {
return true;
}
if (endDate.getMonth() === 10) {
return true;
}
return endDate.getTime() < this.startDate.getTime() ;
}
}
如果我这样使用它,我的问题将得到解决。因为 getMonth() 返回一个数组。如果我的数组索引为真,那对我的问题来说将非常好。
推荐阅读
- java - 滚动视图不滚动布局权重
- javascript - 多台计算机上的 Fullcalendar 自动更新日历
- javascript - 嵌套数组的 JavaScript 递归
- reactjs - create-react-app 与 storybook 6.1.6 集成并且构建有错误
- react-native - 广告未在 iOS 中展示 | 反应原生
- time - istio 日志输出时区可以修改吗?
- python-3.x - 默认值未显示在 html 页面(Flask 表单)中?
- python - 检查列 pyspark df 的值是否存在于其他列 pyspark df
- android - 在没有 Internet 连接的情况下获取当前位置
- go - 如何在谷歌云存储中上传调整大小的图像?