问题
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