它不起作用,因为 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();
});
});
});
}