Check out this code snippet.
$scope.$watch('year', reloadData);
$scope.$watch('month', reloadData);
$scope.year = 2017;
$scope.month = 1;
var reloadData = function() {
/* Refresh Data */
}
var init = function() {
$scope.year = 2015;
$scope.month = 3;
}
init();
How many times do you think the "reloadData" function is called after initialization? Is there a way to trigger reloadData only once when both year and month values are changed simultaneously? For instance:
<input ng-model="year" name="year" id="year">
<input ng-model="month" name="month" id="month">
Changing the year triggers reloadData.
Changing the month triggers reloadData.
Changing both the month and year should only trigger reloadData once.
Thank you!