Check out this code snippet:
$scope.$watch($scope.getWidth, $scope.adjustSidebar);
var adjust = function (newValue, oldValue) {
if (newValue >= mobileView) {
if (angular.isDefined($cookieStore.get('sidebarToggle'))) {
$scope.sidebarToggle = $cookieStore.get('sidebarToggle');
} else {
$scope.sidebarToggle = true;
}
} else {
$scope.sidebarToggle = false;
}
};
When I place the definition of $scope.adjust in as the second argument for $watch, everything runs smoothly. But when I attempt to extract it like this, the code malfunctions (meaning $scope.adjustSidebar doesn't run when the event is triggered). What causes this issue? What makes a difference whether I save the function in a variable and use that variable as the argument or directly input the definition as the argument?
I appreciate your insights.