title: AngularJS $scope variable on window onclick
body: <p>I have a button which when clicked displays a windows and hides it when the button is clicked again.I want the window to close even if any other place in the page is clicked.</p>
  
  <p>This is my code :</p>
  
  <pre><code>&lt;a class="btn dropdown-toggle multiselect-btn" ng-click="content=!content;contentClick=true"&gt;
  
  //The div to show hide
  &lt;div ng-class="{'open':content}" &gt; div content &lt;/div&gt;
  </code></pre>
  
  <p>I wrote the following window on click code in the controller but it didn't work..</p>
  
  <pre><code>$window.onclick = function () {
      if($scope.contentClick){
      $scope.contentClick=0;  
      }
      else{$scope.content=false;
      $scope.$apply();}
  
      }
  </code></pre>
  
  <p>What is the correct way to do this?Can anyone please guide me in the right direction.Thanks.</p>