You can do the following:
<div [ngClass]="classStr"
(click)="classStr='my-class'">
</div>
you will have to add classStr
to your component (just declare it - classStr: string;
inside the component)
notice that this will only add the class once, not toggle it, if you want to toggle, you will have to do something like:
<div [ngClass]="classStr"
(click)="classStr = classStr === 'my-class' ? '' : 'my-class' ">
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…