如何防止ng-click在标签标签上触发两次? [英] How to prevent ng-click's triggering twice on label tag?
本文介绍了如何防止ng-click在标签标签上触发两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击里面有输入的标签时,Angular 的 ng-click 被触发两次.我试过 $event.stopPropagation();
但没有用.我该如何解决这个问题?
我也检查了这个问题:Angular.js 标签上的 ng-click 事件触发了两次
<form role="form" name="selectForm" novalidate><label ng-click="$event.stopPropagation(); updateSelected();"><input type="checkbox" ng-model="chechkedSkins[item.id]"/><span>{{item.name}}</span>标签></表单>
解决方案
使用 ng-change="updateSelected"
仅在输入上使用此选项,因为即使您单击标签也会触发更改.
Angular's ng-click gets triggered twice when I click label which has input inside in it. I've tried $event.stopPropagation();
but didn't work. How do I solve this?
I've checked this question also: Angular.js ng-click events on labels are firing twice
<div class="list-group-item" ng-repeat="item in model.data">
<form role="form" name="selectForm" novalidate>
<label ng-click="$event.stopPropagation(); updateSelected();">
<input type="checkbox" ng-model="chechkedSkins[item.id]" />
<span>{{item.name}}</span>
</label>
</form>
</div>
解决方案
Use ng-change="updateSelected"
Use this only on the input since the change is triggered even if you click the label.
这篇关于如何防止ng-click在标签标签上触发两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文