I use the Ionic Framework for the application and adhere to one thing. In my application, I have a Favorites view, which displays a list of items that the user used elsewhere in the application. The problem is that the code in the controller runs only on the first hit of the Favorites route. If the user adds a favorite place in another place to the application, then returns to the "Favorites" mode, the list is not restored.
In my controller, I have the following:
Favourites.all().then(function(results){ angular.forEach(results, function(value, key){
I have a Factory that executes a database query:
.factory('Favourites', function(DB){ var self=this; console.log("test 1"); self.all = function() { return DB.query('SELECT * FROM favourites') .then(function(result){ return DB.fetchAll(result); }); }; return self; })
My question is: how can I get the favorites controller to be updated after the user has added a new favorite to the database? I tried to add the region reload function to the controller, and also add reload: true for $ stateProvider for the route, but it didn't make any difference.
source share