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>