简体   繁体   English

如何使用angular js在ck编辑器中显示动态内容

[英]How to display dynamic content into ck editor using angular js

ck editor text area
<textarea cols="100" id="editor1" name="editor1" rows="50" data-ng-model="report.reportlist">

</textarea>
<div>{{ report.reportlist }}</div>

I am getting value inside div but not in ck editor 我在div中获得价值,但在ck编辑器中却没有

My controller 我的控制器

$scope.report.reportlist = data ;

data = <p><h1>PRO/AH/EDR> African swine fever - Belarus (03): (HR) 1st rep, OIE, RFI</h1><br/><br/><p>African Swine Fever &mdash; Worldwide/Unknown<br/></p>

I am not getting why it is not showing in CK editor . 我不明白为什么它不显示在CK编辑器中。 I am using angular js 我正在使用angular js

It doesn't work because the content inside the CKEditor isn't actually in the textarea itself (the textarea element gets hidden). 这是行不通的,因为CKEditor内部的内容实际上并不在textarea本身中(textarea元素被隐藏了)。 To keep your scope variable and CKeditor in sync you will need to listen for the CKEditor events and update your scope variable accordingly. 为了使您的范围变量和CKeditor保持同步,您将需要监听CKEditor事件并相应地更新您的范围变量。
I made a quick demo here: http://jsbin.com/iMoQuPe/2/edit 我在这里做了一个快速演示: http : //jsbin.com/iMoQuPe/2/edit

HTML: HTML:

<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div ng-controller="CkCtrl">
    <textarea name="editor" id="" cols="30" rows="10" ng-model="editorData"></textarea>
    <pre>
      {{ editorData }}
    </pre>
  </div>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.0.1/ckeditor.js"></script>
  <script>
    CKEDITOR.replace( 'editor' );
  </script>
</body>
</html>

JavaScript: JavaScript的:

function CkCtrl($scope) {
  // Load initial data, doesn't matter where this comes from. Could be a service
  $scope.editorData = '<h1>This is the initial data.</h1>';

  var editor = CKEDITOR.instances.editor;

  // When data changes inside the CKEditor instance, update the scope variable
  editor.on('instanceReady', function (e) {
    this.document.on("keyup", function () {
      $scope.$apply(function () {
        $scope.editorData = editor.getData();
      });
    });
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM