This should work for you.
In .html:
<div class="my_class" (click)="clickEvent()"
[ngClass]="status ? 'success' : 'danger'">
Some content
</div>
In .ts:
status: boolean = false;
clickEvent(){
this.status = !this.status;
}
More Related Contents:
- Difference between [ngClass] vs [class] binding
- Angular 2 innerHTML (click) binding
- Error:Unable to locate adb within SDK in Android Studio
- Angular 2 – View not updating after model changes
- Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found
- Property ‘map’ does not exist on type ‘Observable’
- Confirm password validation in Angular 6 [duplicate]
- Call child component method from parent class – Angular
- How to disable a input in angular2
- Can’t bind to ‘ngIf’ since it isn’t a known property of ‘div’ [duplicate]
- Angular file upload progress percentage [duplicate]
- Uncaught Error: Unexpected directive ‘MyComboBox’ imported by the module ‘AppModule’. Please add a @NgModule annotation
- Angular 2 – formControlName inside component
- : Unsafe value used in a resource URL context
- access SASS values ($colors from variables.scss) in Typescript (Angular2 ionic2)
- Include assets when building angular library
- Angular 4 – Select default value in dropdown [Reactive Forms]
- How to uninstall/upgrade Angular CLI?
- How to get rid of the warning .ts file is part of the TypeScript compilation but it’s unused
- How can I create an observable with a delay
- Angular 2 Observable with multiple subscribers
- how to turn off differential loading in Angular v8?
- How to update / upgrade from Angular 4 to Angular 5+
- Where does DOM manipulation belong in Angular 2?
- Angular2: use [(ngModel)] with [ngModelOptions]=”{standalone: true}” to link to a reference to model’s property
- Angular 2 Reactive Forms trigger validation on submit
- How to manually set focus on mat-form-field in Angular 6
- What is the difference between fakeAsync and async in Angular testing?
- why lazy loaded module has to import commonModule? Angular 2
- How is Angular’s *ngFor loop implemented?