AngularJS NG-点击两次火灾 [英] AngularJS ng-click fires twice

查看:161
本文介绍了AngularJS NG-点击两次火灾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的NG-点击并两次触发,当我把它应用到SPAN标记。

I am using ng-click and it fires twice when I apply it to SPAN tag.

HTML

<div ng-app="regApp" ng-controller="RegistrationCtrl" data-ng-init="GetEventDetail()" ng-show="data.EventName">

    <h2>Registration for {{data.EventName}}</h2>
    <span class="btn" id="btnSave" ng-click="PostRegistration()">Save </span>

</div>

控制器

var app = angular.module('regApp', ['ui']);

app.controller('RegistrationCtrl', function ($scope, $http) {
    $scope.PostRegistration = function () {
    alert('click '); <--- fires twice
    /// some code here -- 
};

它应该只触发一次。我如何才能找到为什么发生这种情况,如何解决?

It should only fire once. How I can find why this is happening and how to fix it?

推荐答案

您提供的不两次触发事件的code:

The code you've provided does not fire the event twice:

http://jsfiddle.net/kNL6E/ (点击保存

也许你包括角两次?如果你这样做,你会得到两个警报,这里演示:

Perhaps you included Angular twice? If you do that, you'll get two alerts, demonstrated here:

http://jsfiddle.net/kNL6E/1/

这篇关于AngularJS NG-点击两次火灾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆