本文介绍了Angular 2单选按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选中或取消选中单选按钮时,在Angular 2中调用的事件是什么.
What are those events called in Angular 2 when radio button is selected or unselected.
类似
<input type="radio" (select)="selected()" (unselect)="unselected()" />
因此,当我单击组中的一个单选按钮时,它将为新选择触发selected()
,为先前选择触发unselected()
.
So when I click one radio button in a group, it will fire selected()
for the new selection and unselected()
for the previous selection.
推荐答案
有效,
<input type="radio" (change)="handleChange($event)" />
但是您需要更多代码来判断选定"或未选定".
您可以在* .ts文件中尝试此操作:
But you need code more to judge 'selected' or 'unselected'.
You may try this in your *.ts file:
export class Comp {
private _prevSelected: any;
handleChange(evt) {
var target = evt.target;
if (target.checked) {
doSelected(target);
this._prevSelected = target;
} else {
doUnSelected(this._prevSelected)
}
}
}
这篇关于Angular 2单选按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!