During the signup process of my AngularJS application, I continuously update a user object.
Instead of creating separate controllers for each signup step, I have opted to use one controller for all steps as the logic is quite similar and it helps keep the code more organized.
One of the challenges I am facing is with a promise that fetches user information from the database:
.service('userInfo', function ($http, $cookies) {
var userId = $cookies.id;
console.log("UI Cookies", $cookies);
var promise = $http.get('/api/findProfile/' + userId, { cache: false}).
success(function (data) {
var userInfo = data;
console.log("This is fresh data!") // This logs the first time I load my page, but never again
return userInfo;
}).error(function(data) {
console.log("ERROR")
return userInfo
});
return promise;
})
When moving from one signup step to the next, I update the profile information in MongoDB and then load the subsequent page. However, when I navigate to a new page using $location('')
from my controller, I notice that I receive outdated userInfo
which has not been updated in the database. On the other hand, if I do a complete page refresh, I get the correct and updated userInfo
.
Could this be a caching issue? Despite passing {cache: false}
to my $http
promise, I am unable to retrieve fresh data (as indicated by the
console.log("This is fresh data!")
); instead, I seem to be getting cached data.
Is there a way to resolve this without having to force a full-page reload in Angular?