Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 不验证两个日期,即使两个日期都是使用angular js的日期类型_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 不验证两个日期,即使两个日期都是使用angular js的日期类型

Javascript 不验证两个日期,即使两个日期都是使用angular js的日期类型,javascript,html,angularjs,Javascript,Html,Angularjs,我知道问这个问题太傻了,但我很困惑,这是不是不起作用。即使每个值在调试模式下看起来都很好 实际上,我想要实现的是,如果productionStartFrom小于当前日期,则显示错误 控制器 html页面 您可以按照下面的代码进行尝试 $scope.checkDate=function(productionStartFrom){ currentDate = $filter('date')(new Date(), "dd/MM/yyyy", "UTC"); produ

我知道问这个问题太傻了,但我很困惑,这是不是不起作用。即使每个值在调试模式下看起来都很好

实际上,我想要实现的是,如果productionStartFrom小于当前日期,则显示错误

控制器

html页面


您可以按照下面的代码进行尝试

$scope.checkDate=function(productionStartFrom){
        currentDate = $filter('date')(new Date(), "dd/MM/yyyy", "UTC");
        productionStartFrom = $filter('date')(new Date(productionStartFrom), "dd/MM/yyyy", "UTC");
        if(currentDate > productionStartFrom){
            $scope.dateErrMsg="Date cant be less than today";
            console.log("Invalid Date");
        }
        else if(currentDate < productionStartFrom){
            $scope.dateErrMsg="Valid Date";
        }
  }

我猜,您比较日期的方式会导致问题比较有什么问题请确保productionStartFrom是日期类型Yes仅是日期类型。它来自datePicker。因此,这将影响任何请检查我的plunkr链接,这是工作检查控制台日志。
<datepicker date-format="dd/MM/yyyy" selector="form-control">
<input name="productionStartFrom" type="text" ng-model="produce.productionStartFrom"                                                                                  pattern="(0[1-9]|1[0-9]|2[0-9]|3[01])/(0[1-9]|1[012])/[0-9]{4}"
ng-minlength="10" maxlength="10" x-ng-change="checkDate(produce.productionStartFrom)"                                /> </datepicker>
$scope.checkDate=function(productionStartFrom){
        currentDate = $filter('date')(new Date(), "dd/MM/yyyy", "UTC");
        productionStartFrom = $filter('date')(new Date(productionStartFrom), "dd/MM/yyyy", "UTC");
        if(currentDate > productionStartFrom){
            $scope.dateErrMsg="Date cant be less than today";
            console.log("Invalid Date");
        }
        else if(currentDate < productionStartFrom){
            $scope.dateErrMsg="Valid Date";
        }
  }
scope.currentDate={};
scope.checkDate=function(productionStartFrom){
      currentDate = $filter('date')(new Date(), "dd/MM/yyyy", "UTC");
      console.log(currentDate); 
      if(currentDate >= productionStartFrom){
          scope.dateErrMsg="Date cant be less than today";
          alert("Invalid Date");
          scope.myForm.$invalid="true";
      }
      else if(currentDate <= productionStartFrom){
          scope.dateErrMsg="";
      }
}