I am facing a challenge where I need to include the "ng-click" directive within a dynamically generated span element that wraps the selected text.
range = window.getSelection().getRangeAt(0);
var span = document.createElement("span");
$(span) .addClass("comment")
.attr("id", short_id +"_"+ n_comment)
.attr("ng-click", "showComment()")
.append(range.extractContents());
range.insertNode(span);
Although the code above successfully wraps the selection with the span, the ng-click
directive does not seem to work.
Given that the Angular directive is dynamically created, it is necessary to compile it using $compile
. However, in this particular scenario, I am unsure of how to proceed with the compilation.
Could anyone provide guidance on how to overcome this issue? Thank you in advance.