I am creating a forum where the replies are written with AngularJS (ng-repeat). A reply can contain links, and on all links, I have added a ng-click. This ng-click is not fired.
I guess it is because by the time the link is written to the dom, AngularJS is done hooking up functions. Are there any workarounds?
Here is an example: http://plnkr.co/edit/Jg0jVOpPL1LcVPHe5YQz?p=preview
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $sce) {
$scope.htmlBody = '<a href="http://www.google.com" ng-click="testmethod()" target="_blank">This does not work</a>';
$scope.toTrustedHtml = function(htmlCode) {
return $sce.trustAsHtml(htmlCode);
};
$scope.testmethod = function()
{
alert('yes');
}
});
<body ng-controller="MainCtrl">
<a href="http://www.google.com" ng-click="testmethod()" target="_blank">This works</a>
<br /><br />
<p ng-bind-html="toTrustedHtml(htmlBody)"></p>
</body>
Thanks Rasmus