ng-click not working in ng-repeat

Issue

NG-click not firing in ng -repeat. I want to use ngclick to display only the specific element details.

<body ng-app="mainApp" >
     <div ng-app = "mainApp" class="container" ng-controller="TableFilterController">
    <table ng-app = "mainApp" class ="table table-hover"> 
    <tr><th>Id</th><th>Name</th><th>Age</th><th>Role</th></tr>
        <tr ng-repeat="p in details "><td>{{ $index + 1 }}</td><td><a  ng-click="clickMe()">{{p.name}}</a></td><td>{{p.age}}</td><td>{{p.mass}}</td></tr>
    </table>

        </div>
    </body>

js:

var mainApp= angular.module("mainApp", []);

    mainApp.controller('TableFilterController', function($scope) {
    $scope.clickMe = function(){
       alert("hey");
    }

Solution

There can be different-2 scenarios:
1. Remove Duplicate ng-app.

2.Use This Once,this will test if controller is calling onload or not

   mainApp.controller('TableFilterController', function($scope) {
   alert("its Calling");
 $scope.clickMe = function(){
       alert("hey");
    }
  1. Check you have mentioned controller name in routing.
    4.Check your file’s code is loading in browser.

Check these points on first priority otherwise try to create plunker so that everyone can look into your code.

Answered By – RITESH ARORA

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.