Angular ng-click is not working inside ng-table
I have the following simple code:
<table ng-table="tableParams" class="table datagrid">
<tr ng-repeat="requestGroup in tableElements">
<td width="30" style="text-align: left" header="'ng-table/headers/checkbox.html'">
<input type="checkbox" ng-model="checkboxes.items[requestGroup.id]" />
</td>
<td data-title="'Group Name'" sortable="'name'">
{{requestGroup.name}}
</td>
<td data-title="'Description'" sortable="'description'">
{{requestGroup.description}}
</td>
<td data-title="'Actions'">
<div data-ng-click="alert('hello')">Update</div>
</td>
</tr>
</table>
when i'm trying to add click event, it isn't being called.
what am i doing wrong?
Firstly don't iterate over tableElements use $data instead.
Second expression in ng-click attribute is not JavaScript it is Angular Expression witch is like JS but has some differences. That's why you don't have alert function in scope. See more in the docs
@liadlivnat It's nearly impossible to say since we don't know your $scope - this type of question might be better suited for StackOverflow When posting sample code where you don't think a particular thing is working I usually pull it out and put it in a separate plunker that way when I show others they can run through the code.
The global functions aren't available on $rootScope you can put them there but I'd recommend not using them to begin with. Good luck! (Could you close this too)
@maxaon thanks, i know i'm using angular and not JS, but it should work out of the box and i'm not sure what i'm doing wrong, sending me to the docs link won't help much, cause i'm very familiar with the language, ng-click attribute should work on any element, but it doesn't work inside ng-table, and i'm not sure why?
can you explain why using $data is better than tableElements?
@Nate-Wilkins the scope is not relevant i was writing alert inside the function but, let's say its a simple function
$scope.print = function()
{
console.log('hello');
}
it doesn't work, as well.
did you ever use ng-click inside ng-table? how did you do that?
@liadlivnat well the ng-click is on a <div> tag which doesn't help we have to make sure that the div is even clickable. I would try to pull this out into a plunker. Here's my angular base plunker that I use to do angular stuff with.
Make sure that angular is also bootstrapped to the document. (ng-app)