简体   繁体   中英

How to get active class name of a button, in angular (2+)?

I need to get active class name of this button when A) reactive form is submitted B) when this button is clicked

HTML

 <button
  type="button"
  [className]=" condition ? 'classA' : 'classB'
  (click) = "buttonClicked($event)"
>
</button>

TS

buttonClicked(event: Event) {
  console.log(event);
  //get class active class name here i.e. classA or classB
}

The class is set in the view by the condition condition? 'classA': 'classB' condition? 'classA': 'classB' . Therefore, you can just know which class is applied in your TS code by writing const classApplied = this.condition? 'classA': 'classB' const classApplied = this.condition? 'classA': 'classB' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM