首页 > 代码库 > ckeditor+angularjs directive

ckeditor+angularjs directive

var cmsPlus = angular.module(‘cmsPlus‘, []);

cmsPlus.directive(‘ckEditor‘, function() {
  return {
    require: ‘?ngModel‘,
    link: function(scope, elm, attr, ngModel) {
      var ck = CKEDITOR.replace(elm[0]);

      if (!ngModel) return;

      ck.on(‘instanceReady‘, function() {
        ck.setData(ngModel.$viewValue);
      });

      function updateModel() {
          scope.$apply(function() {
              ngModel.$setViewValue(ck.getData());
          });
      }

      ck.on(‘change‘, updateModel);
      ck.on(‘key‘, updateModel);
      ck.on(‘dataReady‘, updateModel);
      ck.on(‘paste‘, updateModel);
      ck.on(‘selectionChange‘, updateModel);

      ngModel.$render = function(value) {
        ck.setData(ngModel.$viewValue);
      };
    }
  };
});

 

ckeditor+angularjs directive