I've got a tooltip type popup everytime text is selected. The problem is angular doesn't recognized dynamically added HTML with angular directives unless they're compiled??? I've got code that modifies the DOM in the controller, creates a textbox and then destroys it. Apparently the Angular way is to do such work in a directive. How should I change my code to do the same as it does below except with the DOM manipulation in a directive???
JS
argapp.controller("AnnotateCtrl", function($scope) {
$scope.newBox = function( rect ) {
var div = document.createElement('div'); // make box
div.setAttribute("class", "shortbox");
div.setAttribute("ng-controller", "EditCtrl");
div.setAttribute("ng-mouseover", "hoverside()");
div.style.border = '2px solid black'; // with outline
div.style.position = 'fixed'; // fixed positioning = easy mode
div.style.top = rect.bottom + 5 + 'px'; // set coordinates
div.style.left = rect.left + 10 + 'px';
div.style.height = '25px';
div.style.width = '64px';
div.innerHTML = "<ng-someOtherthing>"
document.body.appendChild(div);
};
$scope.annotate = function() {
if ( getSelectedText() != "" ) {
killBoxes();
var selection = window.getSelection();
var range = selection.getRangeAt(0);
var rect = range.getBoundingClientRect();
$scope.newBox(rect);
window.setTimeout( killBoxes, 3000);
}
};
})
HTML
<div ng-controller="AnnotateCtrl" ng-mouseup="annotate()" id="tate">
I can be selected.<br>
Lets see how this works.<br>
</div>