We have a problem in updating the data lists on dashboard page after creating a new list in create page. It already saved on the database, but not updating in the views. It updates once i click the refresh button on the browser but this is a one page web app. How can I update the lists on my dashboard page after adding a data from the previous page without refreshing the page? I used couchbase for database.
2 Answers
The problem here is that you are loading the content from your persistent storage, and then it's in angular as-is, and to retrieve any updates you will have to re-fetch it from your persistent storage. Unfortunately, it is not as simple to $watch your back-end.
You have some options here: if you are making your change from within the angular component of the site, then you can just call a function when you are creating a new page which re-fires your db-access code, and refreshes the model.
If you are making changes from outside of angular, then you will need to either use polling to refresh your angular model periodically, or go for a fancier web-socket option, as explained here.
-
I've tried this way, after saving the data on my createpage, i added this code: rootScope.$broadcast('event: list updated', true); location.path('/quizmaster/dashboard'); And when the second page controller notified that broadcast event, it will call the function for displaying the data. rootScope.$on("event: list updated", function(value) { console.log('event update'); // call the gameList function for displaying lists gameList.async(); }); The event is fired when redirected to the second controller(which is the dashboard page) but it doesn't update the lists. – abelski Oct 14 '13 at 10:13
-
Does the gamelist.async function call the database? – B Cotter Oct 14 '13 at 13:23
-
I've created another page for this, provided my code for further understanding. http://stackoverflow.com/questions/19396040/angularjs-result-is-not-updating-when-new-create-data-has-been-added – abelski Oct 16 '13 at 05:57
After reading this question and your other question, my guess would be, that you get the old view from couchbase.
Per default couchbase sets the stale
parameter to update_after
, which results in getting the updated view only after the second access, see the couchbase documentation for more information.
To fix this, it should be sufficient to set stale
to false
.
If you access couchbase via REST call, adding ?stale=false
to the call should do the trick, otherwise add the parameter according to your used SDK specification.