条件不在angularJS控制器中工作

时间:2014-11-28 06:09:58

标签: javascript angularjs

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;
}  
<当前日期和约会日期显示正确,但条件不起作用?

1 个答案:

答案 0 :(得分:0)

好像你正在使用库时刻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的完整解释是here

注意 - 请检查我在此处直接键入的一些拼写错误的代码
注意 - 确保$scope.AppointmentsList[i].J可以通过时刻库

进行解析