In my case, I am using daterangepicker with angular. My purpose is to watch any change in the model that stores the date range value and save it for an AJAX call later. I face the same issue as it hits the event twice whenever the date is change even if it is only Today : Once it is object with startDate and endDate properties, and the other time it is a string.
可以利用这一优势。
$scope.$watch(
rangeOfDate ,
function (newValue) {
// Due to a known bug of open source library daterangepicker, the event is hit twice
//upon change. Once it is an object, and once it is a string. So, use appropriately.
var selectedDateRange = new Object();
if (typeof (newValue) == object ) {
selectedDateRange.startDate = new Date(newValue.startDate).toLocaleDateString();
selectedDateRange.endDate = new Date(newValue.endDate).toLocaleDateString();
//Do as you wish with this custom object
}
else if (typeof (newValue) == string ) {
alert("string");
}
},
false);