Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  18] [ 3]  / answers: 1 / hits: 37543  / 9 Years ago, tue, june 9, 2015, 12:00:00

I am trying to use the Hidden property in Angular2 and when I include a style that alters the display of the DIV, the hidden property is ignored.



When the code below is run, both divs are displayed.
When I remove the class .displayInline the first DIV is hidden and the second is displayed (as expected).



Can I use Hidden and the display CSS together?



import {ComponentAnnotation as Component, ViewAnnotation as View, bootstrap, NgIf} from 'angular2/angular2';

@Component({
selector: 'hello'
})
@View({
template: `<style>.displayInline{ display:inline }</style><span *ng-if=name>Hello, {{name}}!</span>
<div>
<div [hidden]=hideDiv1() class=displayInline>should be hidden.</div>
<div [hidden]=hideDiv2() class=displayInline>should be displayed.</div>
</div>`,
directives: [NgIf]
})
export class Hello {
name: string = 'World';
constructor() {
setTimeout(() => {
this.name = 'NEW World'
}, 2000);
}

hideDiv1(){
return true;
}

hideDiv2(){
return false;
}
}

bootstrap(Hello);


Repository:https://github.com/albi000/ng2-play


More From » angular

 Answers
3

Note: <span>'s default to display: inline, you may want to use them instead.



Currently classes override [hidden]. I agree, this isn't as effective as ng-hide/ng-show and I hope it is fixed in future versions of angular2. It is currently an open on issue on the Angular2 repo.



You can overcome the problem by simply wrapping your [hidden] element with the class.



<span class=someClass>
<span [hidden]=hideDiv1()>should be hidden.</span>
</span>

[#66265] Sunday, June 7, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
johnniejarend

Total Points: 84
Total Questions: 91
Total Answers: 91

Location: British Indian Ocean Territory
Member since Tue, Feb 22, 2022
2 Years ago
;