我从http://fdietz.github.io/recipes-with-angular-js/common-user-interface-patterns/editing-text-in-place-using-html5-content-editable.html中提取的这个指令非常好用。AngularJS contenteditble div - 需要获取插入位置
这是我的代码。
angular
.module('app')
.directive("formulaEditor", function() {
return {
restrict: "A",
require: "ngModel",
link: function(scope, element, attrs, ngModel) {
function read() {
ngModel.$setViewValue(element.html());
}
ngModel.$render = function() {
element.html(ngModel.$viewValue || "");
};
element.bind("blur keyup change", function() {
scope.$apply(read);
});
}
};
});
<div formula-editor id="editor" contenteditable="true" ng-model="kpiForm.formula"></div>
我需要让我的div上的光标位置。我不知道如何实现我发现的代码(不使用角度):Get caret position in contenteditable div including tags
有人可以帮忙吗? ty!
嗨,我正在寻找类似的东西。你有没有找到解决方案? – AshD