title: AngularJS use a directive to prevent other directives to execute
body: <p>Some actions in my Angular app require the user to be registered. If the user is not registered we want to show a "Register modal" and prevent the original action.</p>
  
  <p>Those actions can be triggered via ng-click or any other "click binding" directive (for example the 'modal-toggle' one).</p>
  
  <p>So I found this solution: <a href="https://stackoverflow.com/a/16211108/2719044">https://stackoverflow.com/a/16211108/2719044</a></p>
  
  <p>This is pretty cool but only works with ng-click.</p>
  
  <p>I first wanted to make the "terminal" property of the directive dynamic but couldn't manage to do it.</p>
  
  <p>So the idea was to set "terminal" to true and manually prevent default click action in the directive.</p>
  
  <p>Here is my DOM</p>
  
  <pre><code>&lt;!-- This can work with terminal:true and scope.$eval(attrs.ngClick) (see example above) --&gt;
  &lt;div user-needed ng-click="myAction()"&gt;Do it !&lt;/div&gt; 
  
  &lt;!-- This doesn't work. I can't manage to prevent the modal-toggle to be executed --&gt;
  &lt;div user-needed modal-toggle="my-modal-id-yey"&gt;Show yourself modal !&lt;/div&gt; 
  </code></pre>
  
  <p>And my directive(s) (which don't work...)</p>
  
  <pre><code>// First try (with terminal:true)
  app.directive('userNeeded', function() {
      return {
          priority: -100,
          terminal: true,
          restrict: 'A',
          link: function(scope, element, attrs) {
              element.bind('click', function(e) {
                  if(isRegistered()) {
                      // Here we do the action like scope.$eval or something
                  }
              });
          }
      };
  });
  
  // Second try (with stopPropagation)
  app.directive('userNeeded', function() {
      return {
          priority: -100
          restrict: 'A',
          link: function(scope, element, attrs) {
              element.bind('click', function(e) {
                  if(!isRegistered()) {
                      e.stopPropagation();
                  }
              });
          }
      };
  });
  </code></pre>
  
  <p>...And that's why I'm here. Any idea ?</p>
  
  <p>Thanks a lot.</p>