I am utilizing a data service to handle all my asynchronous data operations. Whenever I click the ERASE button, a function is triggered to erase all data and return an object indicating the operation status (Success: true/false).
If the value returned is TRUE, I want to redirect to another view (such as the Data Successfully Erased page). However, on the first click of the button, the routing does not occur even though the erase function returns the correct value (true). It only triggers the route on subsequent clicks.
Below is how I have implemented my removeDatabase() function from the dataService:
self.removeDatabase = function () {
//$location.path("/setup");
dataService.resetDatabase().done(function (msgs) {
if(msgs['Operation_success']){
console.log("Operation is Success ? :"+msgs['Operation_success']);
$location.path("/setup");
//self.loadSetup();
}
});
},
Here is the function inside the service:
appdata.resetDatabase = function () {
appdata.msgs = {};
var deferred = jQuery.Deferred();
appdata.db = window.openDatabase("finbud_db", "1.0", "FinBud", 20);
... (omitted for brevity)
return deferred.promise();
};
The relevant HTML code snippet:
<md-button ng-click="appCtrl.removeDatabase();">
<i class="mdi mdi-reload"></i> Reset App
</md-button>
Any assistance will be greatly appreciated. Thank you.