Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlockUI during a function in Angular

In a web-app there is a button which call a function. How can I do if I want to insert a blockUI during the operation? Have I do a promise? Where in particular?

$scope.eraseDB = function(){
    database.destroylocalDB();
};

the function:

destroylocalDB: function(){

  localDB.destroy().then(function (response) {        
      //Remove cache
      datacache.dr = [];
      database.initDB();
  }).catch(function (err) { 
      console.log(err);
  });       
}
like image 668
panagulis72 Avatar asked Dec 14 '25 11:12

panagulis72


1 Answers

Have you looked the Angular BlockUI?

Take a look at the documentation. After configuration, you will just need to:

destroylocalDB: function(){
  blockUI.start(); 
  localDB.destroy().then(function (response) {  
      blockUI.stop();      
      //Remove cache
      datacache.dr = [];
      database.initDB();
  }).catch(function (err) { 
      blockUI.stop();
      console.log(err);
  });       
}

EDIT:

To do what you want, you would need to change your service to return the promise:

destroylocalDB: function(){

  return localDB.destroy().then(function (response) {        
      //Remove cache
      datacache.dr = [];
      database.initDB();
  }).catch(function (err) { 
      console.log(err);
  });       
}

So you can:

$scope.eraseDB = function(){
    blockUI.start(); 
    database.destroylocalDB().then(function(){
        blockUI.stop();
    });
};

I didn't test, but it should work.

like image 169
Renan Ferreira Avatar answered Dec 16 '25 00:12

Renan Ferreira