<text-angular name="myEditor" class="deal-notes" ta-
toolbar-class="btn-toolbar pull-right" ng-model-options="{ debounce: 500}"
ng-change="updateDeal('deal.notes');" ng-blur="makeLinks()" ta-toolbar-
group-class="btn-group" ta-toolbar="[['bold','italics', 'insertLink']]" ng-
model="deal.notes">
尝试使用ng-change
创建超链接,但是当用户粘贴URL时,它会将光标移动到开头。
<script>
function makeLinks(){
var linkedText = Autolinker.link($scope.deal.notes, {stripPrefix: false});
$scope.deal.notes = linkedText;
updateDeal('deal.notes');
}
<script>
您需要做的是在对html /文本进行任何修改之前存储插入符号的位置。更改完成后,将插入符号设置回原始位置(或根据更改计算新位置)
所以像这样修改makeLinks()函数
function makeLinks()
{
var caretPosition = editorElement.prop("selectionStart");
var linkedText = Autolinker.link($scope.deal.notes, {stripPrefix: false});
$scope.deal.notes = linkedText;
updateDeal('deal.notes');
// set the cursor back to correct position
editorElement.setSelectionRange(caretPosition, caretPosition);
}