AngularJS ng-click called twice

0

I'm using ng-click to make a common javascript call. However it is being called / triggered twice when I click on the call.

My policy:

angular.module('myApp.directives').directive('cadastrarPost', cadastrarPost);

cadastrarPost.$inject = ['$ionicPopup', '$ionicPopover'];

function cadastrarPost($ionicPopup, $ionicPopover) {

    var ddo = {
        templateUrl: 'pages/ingressos/cadastrarPost.html',
        replace: true,
        restrict: "E",
        link: link,
    }


    function link(scope, element, attrs) {
        function salvar() {
            ...
        }
    }

    return ddo;
}

My 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">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="lib/angular-animate/angular-animate.min.js"></script>
    <script src="lib/angular-sanitize/angular-sanitize.min.js"></script>
    <script src="js/lib/angular-locale_pt-br.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- Aplicação -->
    <script src="js/app.js"></script>

    <!-- Diretivas -->
    <script src="pages/inicio/cadastrarPost.js"></script>

</head>
<body ng-app="MyApp">
    <ion-nav-view>
        <ion-view cache-view="false" can-swipe-back="false">
            <ion-header-bar class="bar-light">
                <span ng-if="!vm.ingresso.id">
                    <button class="button button-clear text-uppercase" ng-click="salvar()">Salvar</button>
                </span>
            </ion-header-bar>
        </ion-view>
    </ion-nav-view>
</body>
</html>
    
asked by anonymous 07.08.2017 / 19:10

1 answer

0

After much research, including this in this long discussion of possibilities ( Here ) I was able to resolve the problem as follows:

  

Switch the ng-click on the IONIC on-tap

From my research, it appears that there is a bug in this ion-header-bar . So much that outside it worked perfectly, in addition, this bug only appeared in versions of Android < 5.x.

Follow the code. Just the fix on the button line.

<ion-nav-view>
        <ion-view cache-view="false" can-swipe-back="false">
            <ion-header-bar class="bar-light">
                <span ng-if="!vm.ingresso.id">
                    <button class="button button-clear text-uppercase" on-tap="salvar()">Salvar</button>
                </span>
            </ion-header-bar>
        </ion-view>
    </ion-nav-view>
    
08.08.2017 / 23:21