Forgive me, I'm new to Angular.
I'm trying to dynamically change the a div when a button is clicked. I have tried [style.width] and [style.width.px]. and it seems to work initially setting the value, but when I try to change it within a function it doesn't seem to be rendering on the screen. Meaning, it changes in the html, but not visually. I have been staring at this too long so some hep would be appreciated.
The div in the html
<div class='logo-contain' [style.width]='logoWidth'>stuff</div>
Where the initial variable is set in the ts file
logoWidth = '450px';
And the function within the ts file
closeSideMenu(){
if(my conditional){
this.logoWidth = '50px;'
}else{
this.logoWidth = '250px;'
}
}
this.logoWidth = '250px';. The semi-colon should not be included in the string. Alternatively, use[style.width.px]="logoWidth", withthis.logoWidth = 250;. There is no reason to use[ngStyle]to set a single style property.[style.width]notation should work. Can you provde a stackblitz of the problem? How do you callcloseSideMenu?