In this plunk I have an HTML table in a variable. I render the table with ng-bind-html
and that works fine. The problem is that I cannot trigger events when cells are clicked. For example, ng-click
at the cell level doesn't call functions declared in AngularJS. How to capture the clicks?
HTML
<div ng-bind-html="html"></div>
Javascript
var app = angular.module('app', []);
app.controller('ctl', function ($scope,$sce) {
var htmlTable = `
<table border="1">
<tr>
<td ng-click="clicked()">
$39,431.67
</td>
<td ng-click="clicked()">
$14,861.50
</td>
<td ng-click="clicked()">
$7,848.97
</td>
<td ng-click="clicked()">
$16,721.20
</td>
</tr>
</table> `;
$scope.html = $sce.trustAsHtml(htmlTable);
$scope.clicked = function(){
alert("cell was clicked");
};
});