[英]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>
我在div中獲得價值,但在ck編輯器中卻沒有
我的控制器
$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 — Worldwide/Unknown<br/></p>
我不明白為什么它不顯示在CK編輯器中。 我正在使用angular js
這是行不通的,因為CKEditor內部的內容實際上並不在textarea本身中(textarea元素被隱藏了)。 為了使您的范圍變量和CKeditor保持同步,您將需要監聽CKEditor事件並相應地更新您的范圍變量。
我在這里做了一個快速演示: http : //jsbin.com/iMoQuPe/2/edit
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的:
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.