I’m trying to use the [ngStyle] directive in an Angular 17 app to dynamically show or hide an element, like this:
<div [ngStyle]="{visibility: loaded ? 'collapse' : 'visible' }">
...
</div>
where loaded
is a boolean property in my component.
The problem is: this doesn’t work. It correctly sets the visibility
property at the start according to the initial value of loaded
, but after that if I at some point change the value of loaded
the visibility doesn’t change accordingly. Am I missing something basic here? I’ve also tried with [style]
instead of [ngStyle]
but the result is exactly the same.