Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a reusable Angular directive that will hide and show a Bootstrap modal.</p> <pre><code>app.directive("modalShow", function () { return { restrict: "A", scope: { modalVisible: "=" }, link: function (scope, element, attrs) { //Hide or show the modal scope.showModal = function (visible) { if (visible) { element.modal("show"); } else { element.modal("hide"); } } //Check to see if the modal-visible attribute exists if (!attrs.modalVisible) { //The attribute isn't defined, show the modal by default scope.showModal(true); } else { //Watch for changes to the modal-visible attribute scope.$watch("modalVisible", function (newValue, oldValue) { scope.showModal(newValue); }); //Update the visible value when the dialog is closed through UI actions (Ok, cancel, etc.) element.bind("hide.bs.modal", function () { scope.modalVisible = false; if (!scope.$$phase &amp;&amp; !scope.$root.$$phase) scope.$apply(); }); } } }; }); </code></pre> <p>Usage Example #1 - this assumes you want to show the modal - you could add ng-if as a condition</p> <pre><code>&lt;div modal-show class="modal fade"&gt; ...bootstrap modal... &lt;/div&gt; </code></pre> <p>Usage Example #2 - this uses an Angular expression in the modal-visible attribute</p> <pre><code>&lt;div modal-show modal-visible="showDialog" class="modal fade"&gt; ...bootstrap modal... &lt;/div&gt; </code></pre> <p>Another Example - to demo the controller interaction, you could add something like this to your controller and it will show the modal after 2 seconds and then hide it after 5 seconds.</p> <pre><code>$scope.showDialog = false; $timeout(function () { $scope.showDialog = true; }, 2000) $timeout(function () { $scope.showDialog = false; }, 5000) </code></pre> <p>I'm late to contribute to this question - created this directive for another question here. <a href="https://stackoverflow.com/questions/19644405/simple-angular-directive-for-bootstrap-modal/19644644#19644644">Simple Angular Directive for Bootstrap Modal</a></p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload