title: How to detect click outside of an element in Angular?
body: <p>This <code>div</code> will be dynamically shown on the page as an east panel when the <code>open panel</code> button is clicked. The bool <code>showEastPanel</code> variable is what is used to open and close the east panel. I am trying to use <code>(clickoutside)</code> to close the panel (setting <code>showEastPanel</code> to false) however the open panel runs first on the <code>Angular</code> hook and the panel is set to true then false and the panel doesn't display. Is the any way to scope <code>clickoutside</code> to not include the button?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div [ngClass]="{'d-none': !showEastPanel, 'east-panel-container': showEastPanel}" (clickOutside)="ClosePanel()"&gt;
        &lt;div id="east-panel"&gt;
          &lt;ng-template #eastPanel&gt;&lt;/ng-template&gt;
        &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;button (click)="ShowPanel()"&gt;Open Panel&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>