In Angular I have a button which toggles a class - What I want to do is add events based on the button class. Should this be done via an If statement within a function? So far my code is below:
HTML button
<!-- toggle button -->
<button type="button" class="btn btn-primary mt-3 ml-3 btn-button" (click)="status=!status; func()" [ngClass]="{'btn-danger' : status, 'btn-primary' : !status}" [disabled]="clicked">{{status ? 'Delete' : 'Add'}}</button>
<!-- toggle button -->
Component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public btn: any;
func () {
if (this.btn.hasClass('btn-primary')) {
alert('Primary clicked');
} else if (this.btn.hasClass('btn-danger')) {
alert('Danger clicked');
}
}
}
statusflag like you already are?