CKEditor not showing when AngularJS swap its view

旧巷老猫 提交于 2020-01-06 18:08:12

问题


My AngularJS Directive is:

.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);
      };
    }
  };

Let's say My View is like following:

<textarea ck-editor  name="menu_content" style="width:600px; height:300px;" id="menu_content" ng-model="models.menu_content" ub-search-settings=""></textarea>

When the view is called CKEditor shows instead of TextArea. It's ok. Now, my problem is CKEditor not showing when view is call for next time not reloading the whole page.


回答1:


Add this to your directive:

          ck.on('instanceReady', function() {
            ck.setData(ngModel.$viewValue);
          });


来源:https://stackoverflow.com/questions/16768473/ckeditor-not-showing-when-angularjs-swap-its-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!