Currently, I have important functionality code within app.run(function...
in Angular:
app.run(function($rootScope, $window) {
// Obtain window dimensions
$window.width = angular.element($window).width();
$window.height = angular.element($window).height();
// Initialize variables
var scrollTimer = false;
// Keydown event listeners
document.onkeydown = function(e){
// Scroll down keys
if (e.keyCode == 32 || e.keyCode == 40) {
scroll(-1);
e.preventDefault(); }
// Scroll up keys
if (e.keyCode == 38) {
scroll(1);
e.preventDefault(); }
}
// Scroll function
function scroll(delta){
// Check scroll timer
if (scrollTimer) return;
// New scroll pane logic
if (delta < 0 && $rootScope.pane.count < $rootScope.pane.max) $rootScope.pane.count += 1;
else if (delta > 0 && $rootScope.pane.count > 0) $rootScope.pane.count -= 1;
else return;
// Apply current pane
$rootScope.$apply();
// Animate scroll movement
var scrollAmount = $rootScope.pane.count * $window.height + "px";
$("html, body").animate({scrollTop: scrollAmount}, 600, "swing");
// Reset scroll timer
scrollTimer = true;
setTimeout(function(){ scrollTimer = false; }, 1500);
}
});
Now, there is a controller (and potentially others) where the goal is to use the scroll()
function. For example:
app.controller("AsideCtrl", function($rootScope, $scope){
// Button scrolling functionality
$scope.scrollTo = function(index){
index = index + 1;
scroll(index);
}
});
It's clear that this setup doesn't work due to $scope
. Is there a simple way to enable this?