
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
ng-click-outside2
Advanced tools
Angular directive for handling click events outside an element.
Like binding to a regular click event in a template, you can do something like this:
<div (clickOutside)="onClickedOutside($event)">My element</div>
npm install --save ng-click-outside2
| Angular | Version | NPM |
|---|---|---|
| 13 | 10.x.x | ng-click-outside2@^10.0.0 |
| 14,15,16 | 11.x.x | ng-click-outside2@^11.0.0 |
| 16,17 | 12.x.x | ng-click-outside2@^12.0.0 |
| 17 | 13.x.x | ng-click-outside2@^13.0.0 |
| 17 | 14.x.x | ng-click-outside2@^14.0.0 |
| 17,18 | 15.x.x | ng-click-outside2@^15.0.0 |
| 18,19 | 16.x.x | ng-click-outside2@^16.0.0 |
| 19,20 | 17.x.x | ng-click-outside2@^17.0.0 |
| 20,21 | 18.x.x | ng-click-outside2@^18.0.0 |
| 21 | 19.x.x | ng-click-outside2@^19.0.0 |
If you use Angular <= 12 please use the original package. https://www.npmjs.com/package/ng-click-outside
| Property name | Type | Default | Description |
|---|---|---|---|
attachOutsideOnClick | boolean | false | By default, the outside click event handler is automatically attached. Explicitely setting this to true sets the handler after the element is clicked. The outside click event handler will then be removed after a click outside has occurred. (Import: NgClickOutsideAttachOutsideDirective) |
clickOutsideEnabled | boolean | true | Enables directive. |
clickOutsideEvents | string | 'click' | A comma-separated list of events to cause the trigger. For example, for additional mobile support: [clickOutsideEvents]="'click,touchstart'". |
delayClickOutsideInit | boolean | false | Delays the initialization of the click outside handler. This may help for items that are conditionally shown (see issue #13). (Import NgClickOutsideDelayOutsideDirective) |
clickOutsideEmitOnBlur | - | - | If enabled, emits an blurWindow event when user clicks outside of applications' window while it's visible. Especially useful if page contains iframes. (Import NgClickOutsideEmitOnBlurDirective) |
clickOutsideExclude | string | A comma-separated string of DOM element queries to exclude when clicking outside of the element. (Import NgClickOutsideExcludeDirective) For example: [clickOutsideExclude]="'button,.btn-primary'". |
Add NgClickOutsideDirective to your imports:
import {NgClickOutsideDirective} from 'ng-click-outside2';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, NgClickOutsideDirective],
bootstrap: [AppComponent]
})
class AppModule {}
You can then use the directive in your templates:
@Component({
selector: 'app',
template: `
<div (clickOutside)="onClickedOutside($event)">Click outside this</div>
`
})
export class AppComponent {
onClickedOutside(e: Event) {
console.log('Clicked outside:', e);
}
}
import {NgClickOutsideDirective} from 'ng-click-outside2';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, NgClickOutsideDirective, NgClickOutsideExcludeDirective],
bootstrap: [AppComponent]
})
class AppModule {}
You can then use the directive in your templates:
@Component({
selector: 'app',
template: `
<div (clickOutside)="onClickedOutside($event)" [clickOutsideExclude]="'.foo'">Click outside this</div>
`
})
export class AppComponent {
onClickedOutside(e: Event) {
console.log('Clicked outside:', e);
}
}
// change imports
import { ClickOutsideModule } from 'ng-click-outside';
// to
import {NgClickOutsideDirective} from 'ng-click-outside2';
// and in Module import
ClickOutsideModule
// to
NgClickOutsideDirective
FAQs
Angular directive for handling click events outside an element.
The npm package ng-click-outside2 receives a total of 19,830 weekly downloads. As such, ng-click-outside2 popularity was classified as popular.
We found that ng-click-outside2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.