javascript - AngularJS - how do show element on odd number of clicks anywhere on browser? -


i have dropdown bar class "navigation-dropdown" shows when variable called "dropdown" true (dropdown value flipped when navbar clicked). way close dropdown click in navbar again. there way close dropdown clicking anywhere in body?

code sample:

 <nav class="navigation-nav hide-mobile" ng-controller="leftnavctrl" ng-click="dropdown=!dropdown">     <h2>dropdown</h2>     <ul class="navigation-dropdown" ng-show="dropdown" ng-click="dropdown=!dropdown">      <li class="navigation-dropdown__item">        <a>account</a>      </li>      <li class="navigation-dropdown__item">       <a>help</a>     </li>   </ul>  </nav> 

you try this:

$(document).on("click", function(e) {     if (!$(e.target).closest(".navigation-nav").length) {         $scope.dropdown = false;     }     $scope.$apply() }) 

it sets value of dropdown false if anywhere on document clicked not .navigation-nav or child of .navigation-nav.

here working fiddle: https://jsfiddle.net/x89dbbw1/7/


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -