makewavesnotwar
makewavesnotwar

Reputation: 1015

Cannot immediately destroy modal elements created with Foundation for Apps

I'm using the ModalFactory included with Foundation for Apps to programmatically create modals which works fine, but my use case requires me to force a redraw of the modal each time it's called. However, when trying to destroy modals, I have found that the source for ModalFactory.destroy includes a 3 second timeout before it destroys the element which seems to be causing all sorts of issues.

I am wondering if there is a workaround for immediately destroying the element.

// ModalFactory.destroy source:      
function destroy() {
    self.deactivate();
    setTimeout(function() {
      scope.$destroy();
      element.remove();
      destroyed = true;
    }, 3000);
    foundationApi.unsubscribe(id);
}

Upvotes: 1

Views: 438

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

As you are using setTimeout function which is JavaScript native function, by running which your digest cycle will not fire the digest cycle. Resultant will be binding will not work if you have changed any scope level object. For avoiding such problem angular has provided $timeout service which work as that of same as setTimeout only does run digest cycle after callback time completed.

// ModalFactory.destroy source:      
function destroy() {
    self.deactivate();
    $timeout(function() {
      scope.$destroy();
      element.remove();
      destroyed = true;
    }, 3000);
    foundationApi.unsubscribe(id);
}

Upvotes: 1

Related Questions