At the start of my application, I need to execute a routine using user data that is fetched during initialization.
In the controller for the homepage, I check if there is a token stored (indicating a logged-in user) and then proceed to run the routine if $scope.currentUser already exists. If not, I set up a watch on it to trigger once the AJAX call returns the necessary data.
However, I am encountering an issue where the $watch callback never gets triggered after its initial setup.
Below is the code for the Feed Controller:
if (sessionStorage.getItem('token'))
{
if ($scope.currentUser) {getItems()}
else {$scope.$watch('currentUser', popFeed()) }
}
function delayForUser()
{
if ($scope.currentUser) {popFeed()}
}
And here is the code for the Application Controller:
if (sessionStorage.getItem('token') && sessionStorage != 'null')
{
UserSvc.getUser()
.then(function (response)
{
$scope.currentUser = response.data
})