title: angularjs calling modal dialog from directive
body: <p>I've created a directive to open a modal dialog. Here's the code:</p>
  
  <p><strong>[EDIT]</strong>  JSFIDDLE HERE: <a href="http://jsfiddle.net/graphicsxp/fcQZk/8/" rel="nofollow">http://jsfiddle.net/graphicsxp/fcQZk/8/</a></p>
  
  <p>PROBLEM: THE CLOSE BUTTON DOES NOT CLOSE THE MODAL.</p>
  
  <pre><code>angular.module('person.directives').
  directive("person", function($dialog) {
  return {
      restrict: "E",
      templateUrl: "person/views/person.html",
      replace: true,
      scope: {
          myPerson: '='
      },
      link: function (scope, element, attrs) {
  
      },
      controller: function ($scope)
      {            
          $scope.opts = {
              backdrop: true,
              keyboard: true,
              backdropClick: true,
              templateUrl: 'person/views/searchPerson.html'
          };
  
          $scope.openDialog = function () {
              var d = $dialog.dialog($scope.opts);
              d.open().then(function (result) {
                  if (result) {
                      alert('dialog closed with result: ' + result);
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>});</p>
  
  <p>That works fine. Now, in the dialog, I use another directive:</p>
  
  <pre><code> &lt;search-person&gt;&lt;/search-person&gt;
  </code></pre>
  
  <p>and the js : </p>
  
  <pre><code>angular.module('person.directives').directive("searchPerson", function ($dialog) {
  return {
      restrict: "E",
      template: "&lt;div&gt;some template&lt;/div&gt;",
      scope: {},
      link: function (scope, element, attrs) {
  
      },
      controller: function ($scope)
      {
          $scope.close = function (result)
          {
              $dialog.close(result);
          }
      }
  }
  });
  </code></pre>
  
  <p>But $dialog.close(result) does not do anything. I've noticed that $scope.close is null.
  I suspect it's got something to do with the injection. I'm injecting $dialog into the searchPerson directive, whereas I guess I should be using the dialog opened from the person directive. I just don't know... Any idea ? </p>
  
  <p><strong>[EDIT 2]</strong></p>
  
  <p>I've replaced the template of the modal by  and the template of the directive searchPerson. Now I don't have scope issue (see updated jsfiddle). But the close button still doesn't work !  the error is:</p>
  
  <pre><code>Object #&lt;Object&gt; has no method 'close'
  </code></pre>
  
  <p>seems like the $dialog is not injected properly in the searchPerson directive .... </p>