我正在尝试比较酒店登记和结账的2个日期,我使用bootstrap UI DatePicker,但由于某些原因我的代码对我不起作用,请指出我的代码有什么问题?感谢
$scope.$watch('lodging.checkIn',function(newVal,oldVal){
var checkinDate = new Date(newVal);
var checkoutDate = new Date($scope.lodging.checkOut);
if(checkinDate < checkoutDate){
$scope.lodging.lastNightBilled = false;
$scope.disableLastNight = false;
}else if(checkinDate == checkoutDate){
$scope.lodging.lastNightBilled = true;
$scope.disableLastNight = true;
}else{
$scope.lodging.lastNightBilled = false;
$scope.disableLastNight = false;
}
});
$scope.$watch('lodging.checkOut',function(newVal,oldVal){
var checkinDate = new Date($scope.lodging.checkIn);
var checkoutDate = new Date(newVal);
if(checkinDate < checkoutDate){
$scope.lodging.lastNightBilled = false;
$scope.disableLastNight = false;
}else if(checkinDate == checkoutDate){
$scope.lodging.lastNightBilled = true;
$scope.disableLastNight = true;
}else{
$scope.lodging.lastNightBilled = false;
$scope.disableLastNight = false;
}
});
HTML:
<div class="datebox">
<input type="text" show-button-bar='false'
class="form-control biginput" datepicker-popup
ng-model="lodging.checkIn" is-open="checkin"
ng-required="true" close-text="Close"
/>
<span class="dateicon" style='right:5px;' ng-click="openCheckIn($event)"></span>
</div>
<label class='ecom-label'>Check-In Date*</label><span ng-show='isCheckOutValid' class='floatright checkedicon'></span>
</div>
<div class="col-a datefloat" >
<div class="datebox">
<input type="text" show-button-bar='false'
class="form-control biginput" datepicker-popup
ng-model="lodging.checkOut" is-open="checkout" min-date='lodging.checkIn'
ng-required="true"
close-text="Close" />
<span class="dateicon" style='right:5px;' ng-click="openCheckOut($event)"></span>
</div>
我做了一些断点,发现它总是忽略比较条件,结果总是:
$ scope.lodging.lastNightBilled = false; $ scope.disableLastNight = false;
任何理想?