通过 ng-click 调用 $scope 的方法:被 IE 执行两次 [英] $scope's method called via ng-click: executed twice by IE
本文介绍了通过 ng-click 调用 $scope 的方法:被 IE 执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的控制器中:
$scope.homeAction = function() {
console.log("HomeAction");
};
在我看来:
<button ng-click="homeAction()">call homeAction()</button>
单击按钮时,Chrome 和 Firefox 会按预期执行该方法,但 IE 会执行两次.知道为什么吗?
When clicking the button, the method gets executed as expected by Chrome and Firefox, but IE executes it twice. Any idea why?
这是一个重现该问题的 plunker:http://plnkr.co/edit/pedZKjIVGDAYfMl0ZphJ.
Here is a plunker that reproduces the issue: http://plnkr.co/edit/pedZKjIVGDAYfMl0ZphJ.
推荐答案
只需将 type="button"
添加到您的按钮即可修复.默认行为是提交,显然这会干扰您的代码.
Just add type="button"
to your button and it should be fixed. Default behaviour is submit and apparently that messes with your code.
<ion-view title="Home">
<ion-content padding="true">
<button type="button" ng-click="homeAction()" class="button button-block button-positive">call homeAction()</button>
</ion-content>
</ion-view>
这篇关于通过 ng-click 调用 $scope 的方法:被 IE 执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文