我正在研究mat-datepicker
用户可以在哪里输入值并使用我的代码选择日期它工作正常。默认情况下,我有一个更新按钮,它将处于禁用模式。当用户满足两个条件时,只有更新按钮才会启用。
这是我的屏幕截图,它看起来像
如果我清除最后一个日期,一旦用户输入最后一个日期,更新按钮将处于禁用模式,那么只有更新将在此处启用我遇到了问题
这是我的 ts 代码
dateValidator(input) {
//console.log(input);
console.log(Object.prototype.toString.call(input) === '[object Date]', !this.disableDate(), input.length > 0)
if (!!input) { // null check
if (Object.prototype.toString.call(input) === '[object Date]' && !this.disableDate() && input.length > 0) {
this.disableUpdateBtn = false;
console.log("Date is Valid!!");
} else {
this.disableUpdateBtn = true;
console.log("Date is Invalid!!");
}
} else {
this.disableUpdateBtn = true;
console.log("Date is Invalid!!");
}
}
这是我HTML
的更新按钮代码
<button mat-flat-button color="primary" (click)="updateMilestone();" cdkFocusInitial [disabled]="disableUpdateBtn">
Update
</button>
单击清除按钮时出现错误,然后开始输入日期,然后输入01
. 我没有收到任何错误,但是当我开始输入Dec
.
我正在检查 if 条件中的输入是否为 null 为什么仍然无法读取 null 属性