Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Check this solution, you dont need a extra controller or angular-ui for that only pass a simple handler and use it</p> <h2>example.js</h2> <pre><code>angular.module('plunker', [], function() { }) .directive('modal', function() { return { restrict : 'E', templateUrl: 'myTpl.html', transclude: true, controller: function($scope) { // you need get a better unique generator $scope.modal_id = 'modal_' + Math.floor((Math.random()*100+1)); $scope.handler = $scope.modal_id; }, scope : { handler : '=' } }; }) .run(); </code></pre> <h2>index.html</h2> <pre><code>&lt;!doctype html&gt; &lt;html ng-app="plunker"&gt; &lt;head&gt; &lt;link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"&gt; &lt;/head&gt; &lt;body&gt; &lt;div ng-init="handler = null"&gt; &lt;modal handler="handler"&gt; &lt;h1&gt;Content&lt;/h1&gt; &lt;/modal&gt; &lt;a href="#{{handler}}" role="button" class="btn primary" data-toggle="modal"&gt;Open me&lt;/a&gt; &lt;/div&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"&gt;&lt;/script&gt; &lt;script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"&gt;&lt;/script&gt; &lt;script src="example.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h2>myTpl.html</h2> <pre><code>&lt;div id="{{modal_id}}" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="{{modal_id}}Label" aria-hidden="true"&gt; &lt;div class="modal-header"&gt; &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt; &lt;h4 id="{{modal_id}}Label"&gt;I'm a modal!&lt;/h4&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; &lt;div ng-transclude&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Cancel&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>look how works in <a href="http://plnkr.co/edit/7opZuK?p=preview" rel="nofollow">plunker</a></p>
 

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