0

使用这个问题的解决方案:Bind Ckeditor value to model text in angularjs and rails

每当我尝试在我的页面上使用该指令时,我都会收到以下错误。

Uncaught TypeError: Cannot call method 'unselectable' of null ckeditor.js:290
a ckeditor.js:290
(anonymous function) ckeditor.js:286
i ckeditor.js:10
CKEDITOR.event.CKEDITOR.event.fire ckeditor.js:12
CKEDITOR.editor.CKEDITOR.editor.fire ckeditor.js:13
CKEDITOR.event.CKEDITOR.event.fireOnce ckeditor.js:12
CKEDITOR.editor.CKEDITOR.editor.fireOnce ckeditor.js:13
(anonymous function) ckeditor.js:222
n ckeditor.js:202
CKEDITOR.scriptLoader.load ckeditor.js:202
(anonymous function) ckeditor.js:221
(anonymous function) ckeditor.js:209
(anonymous function) ckeditor.js:207
n ckeditor.js:202
CKEDITOR.scriptLoader.load ckeditor.js:202
CKEDITOR.resourceManager.load ckeditor.js:206
f ckeditor.js:208
(anonymous function) ckeditor.js:209
n ckeditor.js:219
(anonymous function) ckeditor.js:219
(anonymous function) ckeditor.js:396
(anonymous function) ckeditor.js:207
n ckeditor.js:202
o ckeditor.js:202
q ckeditor.js:202
(anonymous function)

我正在使用以下指令

var app = angular.module('Tutorial', [])
    .config(function($routeProvider, $locationProvider) {
    $routeProvider
        .when(/*routes like this */)
        .otherwise({ redirectTo: '/' })
})

app.directive('ckEditor', function() {
  return {
    require: '?ngModel',
    link: function(scope, elm, attr, ngModel) {
      var ck = CKEDITOR.replace(elm[0]);

      if (!ngModel) return;

      ck.on('pasteState', function() {
        scope.$apply(function() {
          ngModel.$setViewValue(ck.getData());
        });
      });

      ngModel.$render = function(value) {
        ck.setData(ngModel.$viewValue);
      };
    }
  };
});

然后在我的页面上

    <script src="/javascripts/ckeditor/ckeditor.js"></script>

    <textarea ck-editor ng-model="variableName"></textarea>

我是 Angular 和 ckeditor 的新手,所以我不太明白这里发生了什么。我只需要将编辑器放到页面上并绑定到我的模型。如果有人知道可能导致此错误的原因,那将对我有很大帮助。

谢谢。

更新:在@sza 评论说小提琴有效之后,我验证它实际上是我的代码中的其他内容。

我将损坏页面的链接添加到另一个页面,以便我可以轻松导航到问题页面,并且编辑器可以正确加载。

    onclick="location.href=&quot;/#/controller/view&quot;"

但是,每当我直接通过 url 导航到该位置时,编辑器都不起作用。

4

0 回答 0