I am facing an issue with a directive that contains dynamic text. My goal is to be able to include ng-click directives in order to trigger functions from the text. I have learned that the recommended approach to achieve this is by compiling the HTML into a template. However, when attempting to do so, I encounter an infinite loop:
angular.module('app')
.directive('times', ['$compile', function ($compile) {
return {
restrict: 'E',
link: function postLink(scope, element, attrs) {
scope.selectDay = function() {
console.log("Clicked on directive");
}
var content = element.html("<div><span ng-click='selectDay()'>Some test content</span></div>");
var compiled = $compile(content);
element.append(content);
compiled(scope);
}
};
}]);