js版本:

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);
};
}
};
});

typeScript版本:

export interface ckeditorDirectiveInterface extends ng.IAttributes {
ckeditorDirective: string;
} export class ckeditorDirective implements ng.IDirective {
restrict = "A"; constructor(private $log: ng.ILogService, private $parse: ng.IParseService, private $window: GlobalDefinitionInterface) {} static instance(): ng.IDirectiveFactory {
const directive = ($log: ng.ILogService, $parse: ng.IParseService, $window: GlobalDefinitionInterface) =>
new ckeditorDirective($log, $parse, $window);
directive.$inject = ['$log', '$parse', '$window'];
return directive;
}
require = '?ngModel';
link = (scope: ng.IScope, elm: Element, attrs: ckeditorDirectiveInterface, ngModel: ng.INgModelController): void => {
let $log = this.$log;
let $window = this.$window;
let element = angular.element(elm);
$log.debug("CKeditor version number:"+CKEDITOR.version); $log.debug((<any> CKEDITOR.instances)["content"]); //如果CKEDITOR已经创建存在则执行destroy
if ((<any> CKEDITOR.instances)["content"]) {
(<any> CKEDITOR.instances)["content"].destroy();
} $log.debug((<any> CKEDITOR.instances)["content"]); //保持始终创建新的CKEDITOR
var ckeditor = CKEDITOR.replace(<HTMLTextAreaElement> element[0]); $log.debug((<any> CKEDITOR.instances)["content"]);
if (!ngModel) return;
ckeditor.on('instanceReady', function () {
ckeditor.setData(ngModel.$viewValue);
}); function updateModel() {
//输入内容更新到model
scope.$apply(function(){
ngModel.$setViewValue(ckeditor.getData());
$log.debug(ckeditor.getData());
});
} ckeditor.on('change', updateModel);
ckeditor.on('key', updateModel);
ckeditor.on('dataReady', updateModel);
ckeditor.on('paste', updateModel);
ckeditor.on('selectionChange', updateModel);
ngModel.$render = function () {
ckeditor.setData(ngModel.$viewValue);
}; } }

ckeditor+angularjs directive的更多相关文章

  1. 学习AngularJs:Directive指令用法

    跟我学AngularJs:Directive指令用法解读(上) http://blog.csdn.net/evankaka/article/details/51232895 跟我学AngularJs: ...

  2. angularjs directive 实例 详解

    前面提到了angularjs的factory,service,provider,这个可以理解成php的model,这种model是不带html的,今天所说的directive,也可以理解成php的mo ...

  3. 学习AngularJs:Directive指令用法(完整版)

    这篇文章主要学习AngularJs:Directive指令用法,内容很全面,感兴趣的小伙伴们可以参考一下   本教程使用AngularJs版本:1.5.3 AngularJs GitHub: http ...

  4. Angularjs directive全面解读(1.4.5)

    说到Angularjs directive即指令,可以这么说Angularjs的灵魂就是指令,学会Angularjs指令那么你的Angularjs的武功就修炼了一半了,当然这只是鄙人的一点点独到见解, ...

  5. angularjs directive (自定义标签解析)

    angularjs directive (自定义标签解析) 定义tpl <!-- 注意要有根标签 --> <div class="list list-inset" ...

  6. 步入angularjs directive(指令)--点击按钮加入loading状态

    今天我终于鼓起勇气写自己的博客了,激动与害怕并存,希望大家能多多批评指导,如果能够帮助大家,也希望大家点个赞!! 用angularjs 工作也有段时间了,总体感觉最有挑战性的还是指令,因为没有指令的a ...

  7. AngularJS Directive 隔离 Scope 数据交互

    什么是隔离 Scope AngularJS 的 directive 默认能共享父 scope 中定义的属性,例如在模版中直接使用父 scope 中的对象和属性.通常使用这种直接共享的方式可以实现一些简 ...

  8. [译]angularjs directive design made easy

    原文: http://seanhess.github.io/2013/10/14/angularjs-directive-design.html AngularJS directives很酷 Angu ...

  9. AngularJS directive 指令相关记录

    .... .directive('scopeDemo',function(){ return{ template: "<div class='panel-body'>Name: ...

随机推荐

  1. Play Framework 完整实现一个APP(八)

    创建Tag标签 1.创建Model @Entity @Table(name = "blog_tag") public class Tag extends Model impleme ...

  2. CSS3 box-sizing

    请在火狐浏览器测试,其他浏览器不一定有效 <!DOCTYPE html > <html > <head> <meta charset="utf-8& ...

  3. JDK1.3安装出现/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory Done.

    今天是出道以来第一次安装JDK1.3,大学的时候接触的也已是JDK1.4,而且是在Red Hat Enterprise Linux Server release 6.6上,安装JDK1.3是由于软件组 ...

  4. 深入解析SQL Server并行执行原理及实践(下)

    谈完并行执行的原理,咱们再来谈谈优化,到底并行执行能给我们带来哪些好处,我们又应该注意什么呢,下面展开. Amdahl’s  Law 再谈并行优化前我想有必要谈谈阿姆达尔定律,可惜老爷子去年已经驾鹤先 ...

  5. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理7

    做完角色之后接下来做先做页面按钮的增加.删除.修改.这里用到的功能和角色那边是一样的.就不多说了.直接上代码. 后台控制器代码 using AuthorDesign.Web.App_Start.Com ...

  6. 1. 什么是Docker?

    ##### 一.什么是Dokcer?> Docker是一个开源项目, 诞生于2013年初, 最初是dotCloud公司内部的一个业余项目. 它基于Google公司推出的Go语言实现. 项目后来加 ...

  7. VIM 常用命令

    1.当vi打开时默认为命令模式,要转入输入模式,需要按a或者i键. 命令模式下: :wq  保存并且退出 :w   只保存不推出 :q   不保存退出 :q!  不保存强制退出 :wq! 保存并强制退 ...

  8. 图像处理工具V1.0

    图像处理工具V1.0(仿彗星图片处理工具.VS2015安装界面)----个人无聊作品 以下是界面: 部分代码一.(摘自网络----加水印代码): public static void ImageWat ...

  9. Java的String中的subString()方法

    方法如下: public String substring(int beginIndex, int endIndex) 第一个int为开始的索引,对应String数字中的开始位置, 第二个是截止的索引 ...

  10. java异常面试题

    1.try{}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后? 也许你的答案是在return之前,但往更细地说, ...