ng-click-outside icon indicating copy to clipboard operation
ng-click-outside copied to clipboard

exclude don't work

Open veronesecoms opened this issue 6 years ago • 3 comments

I have one element (#informacao) that i don't need to fire the clickout event.

This is my code:

    <div [exclude]="'#informacao'" (clickOutside)="teste()" id="cardnotificacao" *ngIf="mostraNotificacoes" class="card cardnotificacoes animated zoomIn">
        <div *ngIf="temNotificacao" class="block-success"><i class="fa fa-clock-o mr-2 iconclock"></i>14:35: Seu plano foi renovado! Obrigado por utilizar o sistema. :) <i (click)="limpaNotificacao()" id="informacao" class="fa fa-close fecharnotificacao ml-2"></i></div>
        <div *ngIf="!temNotificacao" class="block-success animated fadeIn"><i class="fa fa-thumbs-o-up mr-2 iconclock"></i>Você não possui novas notificações!</div>
    </div>

I also try:

<div [exclude]="'.fa'" (clickOutside)="teste()"

and:

<div [exclude]="'.fa,.fa-close,.fecharnotificacao,.ml-2'"

But the event is triggered when i click in my i element

veronesecoms avatar Sep 13 '18 20:09 veronesecoms

@veronesecoms ng-click-outside seems to cache the DOM nodes that are excluded by default. It seems like there may be more efficient ways of doing this exclude check but I'll ignore that for now.

To fix this, try setting:

<... [excludeBeforeClick]="true" ...>

This will be sure to recreate the exclude list after each click ensuring that created elements (such as your element by the ngIf) is registered.

Hope that helps!

dbrody avatar Jul 11 '19 23:07 dbrody

[excludeBeforeClick]="true" didn't help I am having a modal with ng-select where if I click the dropdown - it is considered as an outside click

saeed-abdul-rahim avatar Nov 05 '20 14:11 saeed-abdul-rahim

In click outside event you can check the event target and can handle the closing functionality of the modal with it! It worked for me. For example:

if (!(event.target as HTMLElement).classList.contains('ng-option')) {
     this.closeProductsList();
}

ghost avatar Aug 04 '21 11:08 ghost