Angular playground
HTML
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-sanitize.js"></script>
<div ng-controller="GreetingController" data-ng-init="init()" >
<div id="dynamic" ng-bind-html="message" />
</div>
<button ng-click="init()">click me - recompile</button>
JavaScript
var myApp = angular.module('myApp', ['ngSanitize']);
myApp.controller('GreetingController', ['$scope', '$sce', '$compile',
function ($scope, $sce, $compile) {
var json = {
"key": {
"text": "<p>For more information, please visit <a href = \"#\" ng-click= \"customizeWindow('http://www.google.com')\">Support</a> .</p>"
}
}
$scope.message = $sce.trustAsHtml(json.key.text);
$scope.customizeWindow = function (url) {
alert('buuuuu');
}
$scope.init = function () {
var el = document.getElementById("dynamic").childNodes[0];
alert(el);
$compile(el)($scope);
};
}]);