[英]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我需要激活 class 时此按钮的名称 A) 提交反应表单 B) 单击此按钮时
HTML HTML
<button
type="button"
[className]=" condition ? 'classA' : 'classB'
(click) = "buttonClicked($event)"
>
</button>
TS 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'
class 是由条件条件在视图中设置的
condition? 'classA': 'classB'
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'
const classApplied = this.condition? 'classA': 'classB'
. const classApplied = this.condition? 'classA': 'classB'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.