javascript - Ionic AngularJS 所有 ng-click 事件都触发两次?

标签 javascript html angularjs ionic-framework

我的 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/

相关文章:

html - 是否可以使用 gulp 将带有特定变量的 scss 提取到 css 中?

javascript - 显示/隐藏 onClick 按钮不起作用

android - 无法读取未定义的属性 'getPicture' - ionic 相机

javascript - es6 - 从一些没有别名的 js 文件中导入所有函数以创建 webpack 包

javascript - jquery改变div背景图片

javascript - 仍然可以在 Firefox 中使用 offcanvas 菜单水平滚动

javascript - AngularJS Ng-repeat,用表达式创建动态 dom

javascript - Firestore Set Catch 最后

php - JQUERY-样式验证

angularjs - Angular 模型的依赖属性