So, this blog is to shed light on a simple yet efficient way on how to open a component as a Modal / Popup inside another component in Angular 9+.
so, let’s see how it’s done!
Prerequisites!
- Should have Angular installed (Install Angular)
- Npm (Node Package Manager) should be installed (Install NPM)
- A text editor or any IDE installed (Click here)
Let’s say you want to open another component on a Modal using a button click. Simple!
There are a few steps you need to follow.
STEP 1 – Create a component that will have a button to open a Modal/Popup (Parent Component)
Let’s create a component which will have the button to open a Modal when clicked. Let’s name this component “parent”. The following command would be entered into a terminal but make sure you are standing inside the directory/folder where you want this component to be made.
Once the component is made let’s just add a dummy HTML code so we can have something to look at. So, let’s go to the child.component.html file and add the following html.
* You can insert a value or a parameter inside the openModal() to pass a value to the function as well.
STEP 2 – Create a component that you want to open inside a Modal/Popup (Child Component)
Let’s create a component that we need to open as a Modal. Let’s name it “child”. Again, make sure that you are standing in the same directory where the parent component was made.
Once the component is made let’s just add a dummy HTML code so we can have something to look at. So, let’s go to the child.component.html file and add the following html.
* ‘anyVariable’ is a parameter that you had passed from the button click function “openModal” in the parent component. This is how you would display that data in the Modal.
STEP 3 – Import that Modal Component inside your Parent Component Along With MatDialog Module
Firstly, we need to install material UI framework using npm. So, run this command on the vscode terminal.
Add this line in the top of the parent component.
Then initialize a variable with the imported module inside the constructor parameters like so:
Lastly, import the child component in the parent component as well.
STEP 6 – Imbed the Parent Component into app-component.html
Go to parent.component.ts file and copy selector value. Should look like this:
Copy “app-parent” it might be different for you if you have named your component something other than “parent”.
Now, just add this selector into the app.component.html file so to embed the parent component which contains only the button into the app.component, which runs at the start of all Angular Projects. Like so.
You’re done!
Now run the project by running the following code into the terminal and click the button to see the Modal.
The output should look like this:
NOTE: If you get dependency or some other type of issue while executing the code, click here. I’ve tackled some of the issues that you might be facing.
That’s a wrap! I hope this tutorial helped you learn how to Open a component as a Modal / Popup inside another component in Angular 9+. You may also want to learn How to Add SweetAlerts in Angular Project or Lazy Loading in Angular 9.
Recent Posts
- Abundența_norocului_și_fortuna_de_a_construi_un_viitor_prosper_și_împlinit
- Šikovná_strategie_fortuna_nabízí_pestré_sázky_a_bonusy_pro_každého_hrá
- Absorbția_riscurilor_financiare_și_fortuna_acumulată_prin_investiții_intelig
- Analiza_skuteczności_strategii_finansowych_z_uwzględnieniem_fortuna_i_długote
- LuckyLouis Casino mobilapp: spil nemt og hurtigt på farten
Recent Comments
Archives
- June 2026
- May 2026
- October 2025
- October 2024
- September 2024
- August 2024
- June 2024
- January 2024
- November 2023
- October 2023
- September 2023
- August 2023
- June 2023
- May 2023
- March 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
Categories
- 21
- aks 1 en
- aks 1 pl
- aks 18
- aks 28
- aks 31
- Angular
- AWS
- Backend Development
- Big Data
- Blog
- Cloud
- crypto 01
- crypto 05
- crypto 15
- crypto 19 en
- crypto 20
- crypto 20.05
- crypto 21.05
- crypto 29
- crypto 5
- Database
- Deployment
- DevOps
- Docker
- fi
- Frontend Development
- GitHub
- Google Cloud Platform
- hu
- Installations
- it
- Java
- JavaScript
- Linux
- MySQL
- Networking
- News
- nl
- no
- NodeJS
- Online casino
- Operating System
- Post
- public
- Python
- Python Flask
- Report
- Security
- Server
- SpringBoot
- Subdomain
- sushicasino 13
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
- Στοιχηματικές
Search
Recent Post
Abundența_norocului_și_fortuna_de_a_construi_un_viitor_prosper_și_împlinit
- 27 June, 2026
- 9 min read
Šikovná_strategie_fortuna_nabízí_pestré_sázky_a_bonusy_pro_každého_hrá
- 27 June, 2026
- 10 min read
Absorbția_riscurilor_financiare_și_fortuna_acumulată_prin_investiții_intelig
- 27 June, 2026
- 8 min read