Javascript 安格拉斯酒店;Bootstrap 3模态-insertText()行为不稳定
根据和,我有以下角度指示 对于正常操作来说,这是非常好的,但只要我尝试使用insertText或insertHtml函数在光标位置插入文本,它的行为就会不稳定。它有时会插入一次文本。。有时两次 有什么想法吗Javascript 安格拉斯酒店;Bootstrap 3模态-insertText()行为不稳定,javascript,angularjs,ckeditor,angularjs-directive,Javascript,Angularjs,Ckeditor,Angularjs Directive,根据和,我有以下角度指示 对于正常操作来说,这是非常好的,但只要我尝试使用insertText或insertHtml函数在光标位置插入文本,它的行为就会不稳定。它有时会插入一次文本。。有时两次 有什么想法吗 注意:所有这些都是在引导模式中完成的。通常,ckEditor在使用angularJS作为指令时工作得非常好 在ckeditor的“粘贴状态”事件中,将值设置为角度模型:- ck.on('pasteState', function () { $timeout(function () {
注意:所有这些都是在引导模式中完成的。通常,ckEditor在使用angularJS作为指令时工作得非常好 在ckeditor的“粘贴状态”事件中,将值设置为角度模型:-
ck.on('pasteState', function () {
$timeout(function () {
ngModel.$setViewValue(ck.getData());
});
});
另一种方法是使用$render函数设置ckEditor的值
ngModel.$render = function (value) {
ck.setData(ngModel.$viewValue);
};
当您使用诸如insertText()或insertHtml()之类的ckEditor函数时,pastestate事件会立即被触发(否则它会在延迟后被调用),一切都会变得很棘手。当第二次调用insertText()并添加两次、三次文本时,它的行为不稳定,以此类推
因此,要使ckEditor与引导模式和AngularJS一起工作,我们必须在关闭模式时使用ckEditor的销毁功能
angular.module('ngTeknorix')
.directive('ckEditor', ['$timeout', function ($timeout) {
return {
require: '?ngModel',
link: function ($scope, $element, $attrs, ngModel) {
$scope.initCkEditor = function () {
var ck = CKEDITOR.replace($attrs.id);
ck.on('pasteState', function () {
$timeout(function () {
ngModel.$setViewValue(ck.getData());
});
});
ngModel.$render = function () {
ck.setData(ngModel.$viewValue);
};
$scope.insertText = function (value) {
ck.insertText(value);
}
};
$scope.destroyCkEditor = function () {
if (CKEDITOR.instances[$attrs.id]) {
CKEDITOR.instances[$attrs.id].destroy(false);
}
};
}
};
}]);
angular.module('ngTeknorix')
.directive('ckEditor', ['$timeout', function ($timeout) {
return {
require: '?ngModel',
link: function ($scope, $element, $attrs, ngModel) {
$scope.initCkEditor = function () {
var ck = CKEDITOR.replace($attrs.id);
ck.on('pasteState', function () {
$timeout(function () {
ngModel.$setViewValue(ck.getData());
});
});
ngModel.$render = function () {
ck.setData(ngModel.$viewValue);
};
$scope.insertText = function (value) {
ck.insertText(value);
}
};
$scope.destroyCkEditor = function () {
if (CKEDITOR.instances[$attrs.id]) {
CKEDITOR.instances[$attrs.id].destroy(false);
}
};
}
};
}]);