I have the following piece of code in Angular:
$rootScope.commands.forEach(function(element, index, array){
commands[element] = function() {alert(element + " Test Command!");}
});
It works when I log into the application for the first time. That is, if I inspect the commands
JSON object, it contains entries from $rootScope.commands
.
The problem comes in when I refresh the page. It is then that I get the error that $rootScope.commands
is undefined.
Why is this happening? Clearly, there is a difference in behavior between logging in the first time and just refreshing the page.
Any ideas?