I am trying to show/hide a div in angular 7 using ng-model and ng-hide but its not working.
button
to Show/Hide- used ng-model
to set expression
<button type="checkbox" ng-model="show" >show/hide</button>
div
to Show/Hide, Used ng-hide
to hide the div
<div class="row container-fluid" ng-hide="show" id="divshow" >
Div Content
</div>
</body>
</html>
I have tried ng-model
and ng-hide
still it's not working.
Please provide a solution
Copy # Angular element = false; We will use *ngIf to display and hide our div based on the condition. As you can see in the above example, we have set a condition if the element is true , the div will be displayed, and if the condition is false , it will not display.
We hide the divs by adding a CSS class called hidden to the outer div called . text_container . This will trigger CSS to hide the inner div.
In our application, we are going to use ngIf and hidden to toggle div on an event of button click. In our Angular application, we can use various versions of Angular such as Angular 6, 7, 8, 9, 10, and 11, to show, use, and hide toggle div on click event.
To hide/show an element in TypeScript, use the style. display property to determine if the element is shown or hidden. If its display property is set to none , show the element by setting it to block , otherwise hide the element by setting its display property to none .
In your HTML
<button (click)="toggleShow()" type="checkbox" >show/hide</button>
<div *ngIf="isShown" class="row container-fluid" id="divshow" >
Div Content
</div>
in your component class add this:
isShown: boolean = false ; // hidden by default
toggleShow() {
this.isShown = ! this.isShown;
}
Try this solution:
Solution 1:
<div *ngIf="show" class="row container-fluid" id="divshow" >
Div Content
</div>
Solution 2:
<div [hidden]="!show" class="row container-fluid" id="divshow" >
Div Content
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With