更新时间:2023-01-29 09:31:41
您已经扭转在第一位的逻辑,你必须从构建一个的startDate新的日期来比较今天的日期。你也设置为CURDATE范围, $ scope.curDate =新的日期()
但随后你被引用为 CURDATE
没有 $范围
所以这是不确定的。最后,你需要投 stateDate
和结束日期
来的日期为好。否则,你只是比较字符串。
You have the logic reversed on the first bit and you have to construct a new date from startDate to compare to today's date. Also you set curDate to the scope, $scope.curDate = new Date()
but then you were referencing it as curDate
without the $scope
so it was undefined. Lastly, you need to cast stateDate
and endDate
to a date as well. Otherwise you're just comparing strings.
$scope.checkErr = function(startDate,endDate) {
$scope.errMessage = '';
var curDate = new Date();
if(new Date(startDate) > new Date(endDate)){
$scope.errMessage = 'End Date should be greater than start date';
return false;
}
if(new Date(startDate) < curDate){
$scope.errMessage = 'Start date should not be before today.';
return false;
}
};