You can do it using ViewChild decorator and Renderer2 service like so:
1) In the component template add a template variable:
<my-element #myElement></my-element>
2) In the ts file:
@ViewChild('myElement') myElement: ElementRef<any> // the argument type can be HTMLElement / HTMLDivElement / component etc.
constructor(private renderer: Renderer2) {}
myMethod() {
this.renderer.setStyle(this.myElement.nativeElement, 'visibility', 'visible');
}
ViewChild, Renderer2, ElementRef must be imported from @angular/core.
You can also use addClass and/or removeClass methods instead of
setStyle for the renderer.
If you are using Angular 8 you need to pass a configuration object as a second argument to the @ViewChild like so:
@ViewChild('myElement', { static: false }). The static property must be set to true if it is used in OnInit life cycle hook (for Angular 9 as well).
<div class="sub-chart" [style.visibility]="condition?'visible':null">` and make the condition true/false. As style has priority over class, you see the "div"