I have three models startDate,endDate,durationMillis in scope. If any of the value is changed by use, I need to calculate the other model by $watch.
$scope.$watch('startDate', function()
{
$scope.endDate = new Date($scope.startDate.getTime() + $scope.durationMillis);
});
$scope.$watch('endDate', function()
{
$scope.durationMillis = $scope.endDate.getTime() + $scope.startDate.getTime();
});
$scope.$watch('durationMillis', function()
{
$scope.startDate = new Date($scope.endDate.getTime() - $scope.durationMillis.getTime());
});
Here, my problem is when user changes start date/end date/duration, $watch of calculated attributes(not changed by user) has been called recursively.