条件在 AngularJS 控制器中不起作用

condition not working in angularJS controller

本文关键字:不起作用 控制器 AngularJS 条件      更新时间:2023-09-26
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear(); 
var currentdate = yyyy+','+mm+','+dd;
var appointmentDate=moment($scope.AppointmentsList[i].J).format('YYYY,MM,DD');
console.log(appointDate)
if (currentdate > appointmentDate ) {
    console.log('test')
    //  $scope.isFutureDate=true;
}  

这里当前日期和约会日期显示正确,但条件不起作用?

似乎您正在使用库时刻js.因此您不必处理JavaScript Date对象或strings

var currentM = moment();
var appointmentM =moment($scope.AppointmentsList[i].J);                
 if (currentM.isBefore(appointmentM)) {
  //  $scope.isFutureDate=true;
 }

或者,为了缩短您的代码,您可以这样做

 if (moment().isBefore($scope.AppointmentsList[i].J)) {
  //  $scope.isFutureDate=true;
 }
时刻

的完整解释 isBefore在这里

注意 - 请检查代码是否有一些错别字,我直接在这里输入了它
注意 - 确保$scope.AppointmentsList[i].J可以通过矩库解析