0

I do not know why an error. When you run the ng-click in the ng-repaet, Uncaught ReferenceError occurs. Are you sure you will not know the cause of the click event does not occur?

test.js

var MyApp = angular.module('MyApp', []);

MyApp.controller('MyCtrl', ['$scope', function ($scope) {
    $scope.add = function() {
        alert("add click");
    };

    $scope.list = function() {
        return [{"1": {id: 1, name: "aaa"},
                "2": {id: 2, name: "bbb"},
                "3": {id: 3, name: "ccc"}}];
    }
}]);

test.html

<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script type="text/javascript" src="test.js"></script>
    <title>Sample</title>
</head>
<body ng-app="MyApp">
    <div class="container" ng-controller="MyCtrl">
        <table class="table table-striped" ng-init="list = list()">
            <tr ng-repeat="element in list">
                <td ng-repeat="nake in element" onclick="add()">{{nake.id}}</td>
            </tr>
        </table>
    </div>
</body>
</html>

Error

Uncaught ReferenceError: add is not defined 
1
  • Use ng-click instead of onclick , like: ng-click="add()" Commented Nov 6, 2014 at 7:07

3 Answers 3

1

You should use the ng-click angular tag, like this:

<td ng-repeat="nake in element" ng-click="add(nake.name)">{{nake.id}}</td>

Check this fiddle to see that it works properly.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to use the ng-click directive instead of onclick.

Comments

0

Use ng-click instead of onclick since any function binded to scope cannot be accessed through onclick event.

<td ng-repeat="nake in element" ng-click="add()">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.