我的 ng-click 事件在我的 Ionic 应用程序中触发了两次,我一直无法弄清楚如何解决这个问题。为了测试这个错误,我将我的代码压缩为以下内容(错误仍然出现在 iOS 模拟器和 iOS 设备上,但不是在浏览器和 android 上):
运行版本(浏览器渲染,不产生错误):play.ionic.io/app/2fc7300bf4a6
JS
(function() {
var app = angular.module('nh-launch', ['ionic']);
app.controller('testCtrl', function($scope) {
$scope.testClick = function () {
alert("hello");
};
});
}());
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>NoHarm Safety Application</title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="lib/angular-resource/angular-resource.js"></script>
<script src="lib/angular-random-string/src/angular-random-string.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="nh-launch">
<ion-pane>
<ion-content>
<div ng-controller="testCtrl">
<button ng-click="testClick()" class="button button-block button-calm">Test Click</button>
</div>
</ion-content>
</ion-pane>
</body>
</html>
非常感谢您的帮助!
最佳答案
这是 ionic 的当前错误。这是由于 alert() 和 $window.alert() 函数。我已将问题发布在这里:https://github.com/driftyco/ionic/issues/4345#issuecomment-139026496
关于javascript - Ionic AngularJS 所有 ng-click 事件都触发两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32466241/