Asma Gheisari
Asma Gheisari

Reputation: 6254

function call in ng-repeat does not render properly

I have this piece of code:

<tr ng-repeat="convention in conventions">
            <td>{{ convention.Id }}</td>
            <td>{{ convention.Title }}</td>
            <td><a href="javascript:void(0)" ng-click="alert(convention.Id)">Edit</a></td>
        </tr>

I wanna call a function like alert and pass Id as parameter.but It does not render properly: firbug

any suggestion?

Upvotes: 1

Views: 44

Answers (2)

potatopeelings
potatopeelings

Reputation: 41065

Add alert to your scope, like so in your controller

$scope.alert = function(i) {
  alert(i)
};

Upvotes: 2

lex82
lex82

Reputation: 11317

Wrap the alert() in a function in your controller and add it to the scope like this:

$scope.handleClick = function(id) {
    alert(id);
}

Then call this function from the template:

ng-click="handleClick(contention.Id)"

Expressions embedded in your templates do only see the functions in the respective scope.

Upvotes: 3

Related Questions