Introduction
In this article, we will learn how to detect an event when clicks outside in a compoent in Angular Application.
Prerequisites
- Basic Knowledge of Angular 2 or higher
- Visual Studio Code
- Node and NPM installed
- Bootstrap
Create an Angular Project
Create an Angular project by using the following command.
Now install Bootstrap by using the following command,
Now open the styles.css file and add Bootstrap file reference. To add a reference in the styles.css file add this line.
Now create a new component by using the following command,
Now open actionmenu.component.html file and add the following code.
Now open actionmenu.component.ts file and add the following code.
Now open actionmenu.component.css file and add the following code.
Now open app.component.html file and add the following code.
Now open app.component.ts file and add the following code.
Now create a new directive by using the following command, and the following code in this directive.
Now open app.module.ts and following code.
Now run the application using npm start and check the result.
![Result]()
Click on button and then click outside anywhere in the component.
Summary
In this article, we learned how to detect event when clicks outside anywhere in the compoent Angular application