I am using textAngular 1.4.1 and I cannot figure out how to insert text into the a textAngular directive at the current cursor location.
I would have thought this was a simple operation.
I have a SELECT with a list of options to insert. When they press the Insert button I want the text to be insert into the HTML at the cursor.
In my controller I have this code
$scope.insertToHtml = function (newText) {
var editor = textAngularManager.retrieveEditor('item_bodyHTML')
$timeout(function(){
editor.scope.displayElements.text.trigger('focus');
rangy.getSelection().getRangeAt(0).insertNode(document.createTextNode(newText))
});
}
HTML:
<div text-angular id="item_bodyHTML" name="item_bodyHTML" placeholder="Body HTML" ng-required="true" data-ng-model="item.bodyHTML" ></div>
<select class="form-control" placeholder="Insert Field" data-ng-model="insertHTML" ng-options="o.code as o.name for o in optionsToInsert"></select>
<button class="btn btn-default" type="button" ng-click="insertToHtml(insertHTML)">Insert</button>
Try with this: