title: Call a controller function from a directive without isolated scope in AngularJS
body: <p>I cannot seem to find a way to call a function on the parent scope from within a directive without using isolated scope. I know that if I use isolated scope I can just use "&amp;" in the isolated to access the function on the parent scope, but using isolated scope when it isn't necessary has consequences. Consider the following HTML:</p>
  
  <pre><code>&lt;button ng-hide="hideButton()" confirm="Are you sure?" confirm-action="doIt()"&gt;Do It&lt;/button&gt;
  </code></pre>
  
  <p>In this simple example, I want to show a JavaScript confirm dialog and only call doIt() if they click "OK" in the confirmation dialog. This is simple using an isolated scope. The directive would look like this:</p>
  
  <pre><code>.directive('confirm', function () {
      return {
          restrict: 'A',
          scope: {
              confirm: '@',
              confirmAction: '&amp;'
          },
          link: function (scope, element, attrs) {
              element.bind('click', function (e) {
                  if (confirm(scope.confirm)) {
                      scope.confirmAction();
                  }
              });
          }
      };
  })
  </code></pre>
  
  <p><strong>But the problem is, because I'm using isolated scope, ng-hide in the example above no longer executes against the parent scope</strong>, but rather in the isolated scope (since using an isolated scope on any directive causes all directives on that element to use the isolated scope). <a href="http://jsfiddle.net/jmcooper/pXej2/" rel="noreferrer">Here is a jsFiddle</a> of the above example where ng-hide is not working. (Note that in this fiddle, the button should hide when you type "yes" in the input box.)</p>
  
  <p>The alternative would be to <strong>NOT use an isolated scope</strong>, which actually is what I really want here since there is no need for this directive's scope to be isolated. The only problem I have is, <strong>how do I call a method on the parent scope if I don't pass it in on on isolated scope</strong>?</p>
  
  <p><a href="http://jsfiddle.net/jmcooper/x5BwG/" rel="noreferrer">Here is a jsfiddle</a> where I am NOT using isolated scope and the ng-hide is working fine, but, of course, the call to confirmAction() doesn't work, and I don't know how to make it work.</p>
  
  <p><strong>Please note, the answer I am really looking for is how to call functions on the outer scope WITHOUT using an isolated scope.</strong> And I am not interested in making this confirm dialog work in another way, because the point of this question is to figure out how to make calls to the outer scope and still be able to have other directives work against the parent scope.</p>
  
  <p><strong>Alternatively, I would be interested to hear of solutions that use an isolated scope if other directives will still work against the parent scope</strong>, but I don't think this is possible.</p>