Suppose I have a customized modal directive that looks like this:
return {
restrict: 'E',
templateUrl: 'modal.html',
scope: {
modalContent: "&",
modalOpen: "&"
}
}
And in the HTML:
<ng-modal modal-content="content" modal-open="active"></ng-modal>
How can I ensure that the modal is not present in the DOM when it is closed, and only gets inserted into the DOM when opened? I need to include the directive in the HTML for it to function properly, but this means the modal is already there even if it's not visible.
I have tried creating a Plunker with my progress so far here, but it only toggles the modal using CSS classes instead of completely removing it.
EDIT:
I have made another version available here, which actually adds and removes the directive from the DOM. This approach involves splitting the logic for adding and removing the directive between the directive itself and an external controller (the controller handles adding the element, while the directive handles removal). Is there a way for the directive to handle all of this on its own?