In Angular, why does ng-click button fire multiple times?

My application has several buttons that look like this:

<ul class="gallery-buttons">
    <li><button class="video-gallery" ng-click="getGallery('video',{{install.id}})"></button></li>
    <li><button class="image-gallery" ng-click="getGallery('image',{{install.id}})"></button></li>
</ul>

      

my controller:

var nanoApp = angular.module('nanoApp', ['ngRoute', 'ngCordova']);
nanoApp
.config(function ($routeProvider, $compileProvider) {
    ...code to setup all my routes using the $routeProvider...
})
.controller('InstallationListController', ["$scope", "$cordovaSQLite", "$rootScope", function ($scope, $cordovaSQLite, $rootScope) {
    document.addEventListener("deviceready", function () {
        ...do some database calls and setup initial $scope...
        $scope.getGallery = function (galleryType, installId) {
            console.log('made it');
        }
    });

});

      

My buttons are part controller

and $scope

, which have ng-repeat

41 items. When I choose one of them, I get console.log

41 times. Even if I move the buttons outside ng-repeat

, so there is only one set, it still fires 41 times.

--- EDIT ---

info on my ng-repeat, note that this is from my template, pulled into mine $routeProvier.when

, and the controller is declared there and not in the container:

<div id="installationlist" class="container">

    <div class="install" section-width directive-scroll-to="{{moveframe}}" get-products install-index="{{$index}}" ng-repeat="install in installations track by $index">
        <div class="details">
            <div class="text">
                <div class="text-container">

                    <p class="industry">Industry: {{install.industry}}</p>
                    <p class="title">{{install.name}}</p>

                    <p class="location">{{install.location}}</p>

                    <div class="product-block">
                        <p class="product" ng-repeat="product in install.products track by $index">{{product.name}}</p>
                        <p class="pixelPitch" ng-if="install.pixelPitch != null">{{install.pixelPitch}}</p>
                    </div>

                    <p class="desc">{{install.instText}}</p>

                </div>
            </div>

            <ul class="gallery-buttons">
                <li><button class="video-gallery" ng-click="getGallery('video',install.id)"></button></li>
                <li><button class="image-gallery" ng-click="getGallery('image',install.id)"></button></li>
            </ul>
        </div>

        <div class="image" style="background-image:url('img/products/nanoslim-bkg.jpg')"></div>
    </div>

</div>

      

+3


source to share





All Articles