Ionic AngularJS所有ng-click事件都会发射两次?

时间:2015-09-08 19:58:17

标签: javascript html angularjs ionic

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

非常感谢帮助!

1 个答案:

答案 0 :(得分:0)

这是离子的当前错误。这是由于alert()和$ window.alert()函数。我已在此处发布了此问题:https://github.com/driftyco/ionic/issues/4345#issuecomment-139026496