I want to add a class to my component when I click a button. So I do it with Renderer2 as following:
this.renderer.addClass(this.elRef.nativeElement, 'photo-removing');
The class only applies when I add the css class in a global css file. It doesn't work when I add it to the component css file. Any idea why does this happen?
Update: Here is my component html:
<div *ngIf="imgMainUrl">
<img
[src]="imgMainUrl"
[style.width.px]="width" [style.height.px]="height"
[ngClass]="{ 'img-radius' : rounded }"
>
<i
[pTooltip]="tooltipTxt" [tooltipPosition]="tooltipPosition"
class="icon-close close-btn"
(click)="removePhoto()">
</i>
</div>
And css:
.photo-removing {
opacity: 0.4;
border:1px solid red;
}