Please review the following code snippet:
front_controller
$scope.month=monthNames[$scope.currentmonthnumber];
monthyeartransfer.setvalue($scope.month);
$scope.monthchange = function(m) {
$scope.month = m;
monthyeartransfer.setvalue($scope.month);
}
Within this controller, I am updating the month value in the monthyeartransfer
service with every click.
The profilecontroller
is accessed as shown below:
profilecontroller
$scope.$watch(function(){
$scope.month = monthyeartransfer.getvalue();
}
However, the above code triggers on every action, even though it should only occur when the month value changes in the service.
I attempted to modify it by:
$scope.$watch('month',function(){
$scope.month = monthyeartransfer.getvalue();
}
Unfortunately, this approach did not work. How can I achieve this functionality? Thank you!