Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can simplify the directive into something like this:</p> <pre><code>changeNotificationApp.directive('onDocumentClick', ['$document', function($document) { return { restrict: 'A', link: function(scope, element, attrs) { var onClick = function() { scope.$apply(function() { scope.$eval(attrs.onDocumentClick); }); }; $document.on('click', onClick); scope.$on('$destroy', function() { $document.off('click', onClick); }); } }; } ]); </code></pre> <p>And then pass a function from the menuController to it:</p> <pre><code>&lt;section class="local-nav" ng-controller="menuController" on-document-click="someFunction()"&gt; </code></pre> <p>No need for the globalController this way.</p> <p>If you want to keep the globalController and handle it from there, you can:</p> <p>1.) Make the menu into a service and then inject it into all controllers that need to be able to control it.</p> <p>2.) Broadcast an event from globalController and listen for it in menuController.</p> <p>Specific alternative solution: You can turn the directive into a 'on-outside-element-click' and use it like this:</p> <pre><code>&lt;ul on-outside-element-click="closeMenus()"&gt; </code></pre> <p>The directive looks like this and will only call <code>closeMenus()</code> if you click outside the <code>ul</code>:</p> <pre><code>changeNotificationApp.directive('onOutsideElementClick', ['$document', function($document) { return { restrict: 'A', link: function(scope, element, attrs) { element.on('click', function(e) { e.stopPropagation(); }); var onClick = function() { scope.$apply(function() { scope.$eval(attrs.onOutsideElementClick); }); }; $document.on('click', onClick); scope.$on('$destroy', function() { $document.off('click', onClick); }); } }; } ]); </code></pre> <p>Working Plunker: <a href="http://plnkr.co/edit/zVo0fL2wOCQb3eAUx44U?p=preview" rel="noreferrer">http://plnkr.co/edit/zVo0fL2wOCQb3eAUx44U?p=preview</a></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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