I am trying to set zindex
for a class using typescript. But it is not working. If you have any idea, please share with me.
ngOnInit() { (<HTMLElement>document.querySelector('.pagemode')).style.z-index = 1;}
I am trying to set zindex
for a class using typescript. But it is not working. If you have any idea, please share with me.
ngOnInit() { (<HTMLElement>document.querySelector('.pagemode')).style.z-index = 1;}
You might be better using inline style binding rather than using querySelector
- depending on the situation
<p [style.z-index]="1">
Some text
</p>
You can use NgStyle directive for set zindex
[ngStyle]="{'z-index':condition ? 9 : 0 }"
You can use NgClass directive rather than manipulating the DOM.
In your Css/Scss file:
.class1 {
z-index: -1;
}
.class2 {
z-index: 1;
}
In your TS file:
YourBooleanVariableNameHere : boolean;
ngOnInit() {
this.YourBooleanVariableNameHere = true;
}
In your Html file:
If your condition is met:
<some-element [ngClass]="{'class1 class2' : YourBooleanVariableNameHere }">...</some-element>
If your condition is not met: Note that there is !
symbol with the variable
<some-element [ngClass]="{'class1' : !YourBooleanVariableNameHere }">...</some-element>
Read Usage Notes for more examples. Refer here for more approaches.,
Or Alternatively you can try the same approach, which is not recommended!
Update:
ngOnInit() {
document.getElementsByClassName("pagemode")[0].style.zIndex = 1;
}