javascript - Destroying an AngularJS $interval which is started in an ngDialog modal -


i have modal showing data table. underlying data updated every few seconds using $http , $interval, when modal showing. using ngdialog library modals. need update stop on modal close, don't know best way trigger destruction. code:

$scope.openmodal = function() {  var refreshmodal = function() {    $http({        params: {proj_id: $scope.projectid},        url: '/projects/_get_data',        method: 'get'    })    .success(function(data, status, headers) {        $scope.modaldata = data.data;        $scope.updatemodal()               })    .error(function(data, status, headers) {        console.log('it didnt work');    });  }  refreshmodal();  $interval( function() { refreshmodal(); }, refreshrate);  ngdialog.open({ template: 'modalid', scope: $scope, classname: 'table-modal', showclose: false });  }; 

how can detect modal closing?

thanks.

the best thing pass instance of $interval modal close event, , upon closing modal, kill it.

something like:

var interval = $interval( function() {refreshmodal(); }, refreshrate); var dialog = ngdialog.open(...); $rootscope.$on('ngdialog.closed', function (e, $dialog) {      //identify if dialog instance closing 1 interval      if ( arethesame(dialog, $dialog) ){           $interval.cancel(interval);      }    }); 

edit: @zbycz another, cleaner solution use fact dialog has closepromise:

var interval = $interval( function() {refreshmodal(); }, refreshrate); var dialog = ngdialog.open(...); dialog.closepromise.then(function(){     $interval.cancel(interval); }); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -