2013-09-30 170 views
1
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編輯器顯示動態內容爲CK編輯如何使用角度JS

我控制器

$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> 

我沒有得到它爲什麼不顯示在CK編輯器中。 我正在使用angular js

+0

我可以問爲什麼* 「非洲豬瘟 - 白俄羅斯」 *? – Cherniv

+0

這是我從服務中獲得的數據,現在我得到了這個問題,我必須重新加載編輯器,每次一旦響應發生變化,但我怎麼不知道 – Prashobh

+0

http://angulartutorial.blogspot.in/2014/03 /integration-of-ck-editor-to-ui.html – Prashobh

回答

2

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

謝謝,http://angulartutorial.blogspot.in/2014/03/integration-of-ck-editor-to-ui.html – Prashobh