Show or hide children components in Angular 10 Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisites: Angular must be installed In this article, we will see how we can show or hide the child components in Angular. Lets start by creating a new project. Create a new folder and initialize a new angular project. Run the project to verify it is working.ng new myProject ng serve -o This will create a new project in the current directory. Now we can clear the app.component.html file and create a child component in order to demonstrate how we can show or hide it.ng generate component comp1 Now the setup part is over. Lets add this components in our app.component.html file:<app-comp1></app-comp1> We will create a button to show and hide the component. Lets add the button code in app.component.html file.<button type="button" (click)="showhideUtility()"> {{buttonTitle}} </button> Here showhideUtility() is a method and buttonTitle is a variable that we need to define in our app.component.ts file. app.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'myProject'; buttonTitle:string = "Hide"; showhideUtility(){ } } Our child component is still blank so lets add some content. Go to comp1.component.html and add the following code: comp1.component.html <div> This is the Child Component </div> And add some css in comp1.component.css in order to get a nice view:div{ height:200px; width: 200px; border: 2px lightblue solid; border-radius: 10px; background-color: lightgreen; }Now coming back to app.component.ts, add a new property 'visible' that will be a boolean variable to define the show/hide state. When user triggers the show hide method, it should flip the value of the 'visible' variable. So finally our app.component.ts will look like this: app.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'myProject'; buttonTitle:string = "Hide"; visible:boolean = true; showhideUtility(){ this.visible = this.visible?false:true; this.buttonTitle = this.visible?"Hide":"Show"; } } Add a ngIf directive to comp1 to show or hide the component. So finally app.component.html looks like this: app.component.html <app-comp1 *ngIf="visible"></app-comp1> <button type="button" (click)="showhideutility()">{{buttonTitle}}</button> Now save all the files and run the project using :ng serve -o The project will run on http://localhost:4200 by default. You will the output like this: When Show button is ClickedWhen Hide Button is Clicked Comment More infoAdvertise with us Next Article AngularJS ng-show Directive M mukulbindal170299 Follow Improve Article Tags : AngularJS AngularJS-Misc Similar Reads Passing data from Child to Parent Component in Angular In Angular, passing data from a child component to its parent component involves emitting events. Essentially, the child component emits an event containing the data that the parent component needs to receive. This is typically achieved using Angular's EventEmitter class, where the child component e 3 min read Use nested Components With Standalone Components in Angular 17 Angular 17 introduced a new feature called Standalone Components, which allows you to create self-contained components that can be used independently without being tied to a specific module. This feature can make your code more modular and easier to maintain. However, when working with Standalone Co 3 min read Angular PrimeNG OverlayPanel Show and Hide Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use Dynamic OverlayPanel Show and Hide in Angular PrimeNG. Over 3 min read AngularJS ng-show Directive The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements. Syntax: <element ng-show="expression"> C 2 min read Component Communication in Angular Angular, as a robust front-end framework, allows you to build complex and interactive web applications by creating reusable components. One of the key aspects of building such applications is effective communication between these components. There are a lot of instances where we need to transfer dat 12 min read Angular PrimeNG Form Calendar Methods Component Angular PrimeNG is an open-source front-end UI framework developed by PrimeTek for developing efficient and scalable angular applications. Using PrimeNG in their projects helps developers to cut down the development time and focus on other important areas of the application. In this article, we will 3 min read Like