My component is defined this way:
import { Component } from 'angular2/core' @Component({ selector: 'sidebar', templateUrl: 'js/app/views/sidebar.html', }) export class SidebarComponent { public sections: boolean[] = [ true, false, false, false, false, false, false, false ]; }
The sidebar.html
template:
<h3 class="proofTitle">...</h3> <p [hidden]="sections[0]"> ... </p> <p [hidden]="sections[1]"> ... </p> ... <p [hidden]="sections[7]"> ... </p>
Seems pretty straight forward, but for some reason, it's showing all of the sections... what am I missing?
The DOM representation of the hidden attribute is a property also called hidden , which if set to true hides the element and false shows the element. Angular doesn't manipulate HTML attributes, it manipulates DOM properties because the DOM is what actually gets displayed.
AngularJS ng-hide Directive The ng-hide directive hides the HTML element if the expression evaluates to true. ng-hide is also a predefined CSS class in AngularJS, and sets the element's display to none .
ngIf will comment out the data if the expression is false. This way the data are not even loaded, causing HTML to load faster. [hidden] will load the data and mark them with the hidden HTML attribute. This way data are loaded even if they are not visible.
The main difference between angular ngIf directive & hidden or display:none is ngIf will add or remove the element from DOM based on condition or expression. hidden attribute in html5 and display none CSS will show or hide the HTML element. We will go through the examples to understand them further.
Check that you don't have any display css rule on your <p>
tags that would override the hidden
behavior like:
p { display: inline-block !important; }
Because the hidden
html attribute behaves like display: none
Just add this code:
p[hidden] { display: none; }
to your styles.css
file.
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