[英]get checkbox state when onChange is triggered
I'm playing in angular and bootstrap. 我在玩角靴。 The question is very trivial.
这个问题很琐碎。 I have input element in my html
我的html中有输入元素
<label><input (change)="callFilt()" type="checkbox"
value="">{{item.name}}</label>
I want to get state of checkbox in my callFilt method.I see that it's possible via ng-model,but I dont want to use any other directives here,is there way to send state of the checkbox? 我想在我的callFilt方法中获取复选框的状态。我看到可以通过ng-model实现,但是我不想在这里使用其他任何指令,是否可以发送复选框的状态?
Neither I want to set id of checkbox and get state via ID in my js code. 我都不希望在我的js代码中设置复选框的ID并通过ID获取状态。
You can create a variabile reference in your markup using the sintax #myInputVariabile and pass it to the function callFilt(checkInput). 您可以使用sintax #myInputVariabile在标记中创建可变引用,并将其传递给函数callFilt(checkInput)。 something like:
就像是:
<label><input (change)="callFilt(checkInput)"
#checkInput type="checkbox" value="">{{item.name}} #checkInput type =“ checkbox” value =“”> {{item.name}}
callFilt(element) {
console.log(element.checked)
}
You can get the value buy putting this inside method 您可以通过将此方法放入内部来获得价值
<label><input (change)="callFilt(this)" type="checkbox"
value="">{{item.name}}</label>
.Now in function 。现在功能
callFilt(e) {
console.log(e.checked); // or
console.log(e.value); //depending input type
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.