diff --git a/build/angular-kindeditor.js b/build/angular-kindeditor.js index 7959a8c..bd8439c 100644 --- a/build/angular-kindeditor.js +++ b/build/angular-kindeditor.js @@ -13,6 +13,7 @@ var linkFn = function (scope, elm, attr, ctrl) { + if (typeof KindEditor === 'undefined') { console.error('Please import the local resources of kindeditor!'); return; @@ -25,9 +26,7 @@ this.loadPlugin('autoheight'); } }; - - var editorId = elm[0], - editorConfig = scope.config || _config; + var editorId = elm[0], editorConfig = scope.config || _config; editorConfig.afterChange = function () { if (!scope.$$phase) { @@ -37,8 +36,20 @@ } }; + if (KindEditor) { - KindEditor.create(editorId, editorConfig); + var editor = KindEditor.create(editorId, editorConfig); + console.log("model value: "+ctrl.$modelValue); + var flag = 2; + scope.$watch(function () { + return ctrl.$modelValue; + }, function(newValue) { + if(flag>0) { + console.log("new value: " + newValue); + editor.html(newValue); + flag--; + } + }); } ctrl.$parsers.push(function (viewValue) { @@ -49,7 +60,7 @@ return { require: 'ngModel', - scope: { config: '=config' }, + scope: { config: '=config'}, link: linkFn }; }); diff --git a/build/angular-kindeditor.min.js b/build/angular-kindeditor.min.js index 9e531ee..a8a7440 100644 --- a/build/angular-kindeditor.min.js +++ b/build/angular-kindeditor.min.js @@ -1,3 +1,3 @@ -/*! angular-kindeditor 2015-04-21 +/*! angular-kindeditor 2016-02-22 author:Zed*/ -!function(a,b){"use strict";b.module("ngKeditor",[]).directive("keditor",function(){var a=function(a,b,c,d){if("undefined"==typeof KindEditor)return void console.error("Please import the local resources of kindeditor!");var e={width:"100%",autoHeightMode:!1,afterCreate:function(){this.loadPlugin("autoheight")}},f=b[0],g=a.config||e;g.afterChange=function(){a.$$phase||d.$setViewValue(this.html())},KindEditor&&KindEditor.create(f,g),d.$parsers.push(function(a){return d.$setValidity("keditor",a),a})};return{require:"ngModel",scope:{config:"=config"},link:a}})}(window,window.angular); \ No newline at end of file +!function(a,b){"use strict";b.module("ngKeditor",[]).directive("keditor",function(){var a=function(a,b,c,d){if("undefined"==typeof KindEditor)return void console.error("Please import the local resources of kindeditor!");var e={width:"100%",autoHeightMode:!1,afterCreate:function(){this.loadPlugin("autoheight")}},f=b[0],g=a.config||e;if(g.afterChange=function(){a.$$phase||d.$setViewValue(this.html())},KindEditor){var h=KindEditor.create(f,g);console.log("model value: "+d.$modelValue);var i=2;a.$watch(function(){return d.$modelValue},function(a){i>0&&(console.log("new value: "+a),h.html(a),i--)})}d.$parsers.push(function(a){return d.$setValidity("keditor",a),a})};return{require:"ngModel",scope:{config:"=config"},link:a}})}(window,window.angular); \ No newline at end of file diff --git a/src/angular-kindeditor.js b/src/angular-kindeditor.js index 7959a8c..bd8439c 100644 --- a/src/angular-kindeditor.js +++ b/src/angular-kindeditor.js @@ -13,6 +13,7 @@ var linkFn = function (scope, elm, attr, ctrl) { + if (typeof KindEditor === 'undefined') { console.error('Please import the local resources of kindeditor!'); return; @@ -25,9 +26,7 @@ this.loadPlugin('autoheight'); } }; - - var editorId = elm[0], - editorConfig = scope.config || _config; + var editorId = elm[0], editorConfig = scope.config || _config; editorConfig.afterChange = function () { if (!scope.$$phase) { @@ -37,8 +36,20 @@ } }; + if (KindEditor) { - KindEditor.create(editorId, editorConfig); + var editor = KindEditor.create(editorId, editorConfig); + console.log("model value: "+ctrl.$modelValue); + var flag = 2; + scope.$watch(function () { + return ctrl.$modelValue; + }, function(newValue) { + if(flag>0) { + console.log("new value: " + newValue); + editor.html(newValue); + flag--; + } + }); } ctrl.$parsers.push(function (viewValue) { @@ -49,7 +60,7 @@ return { require: 'ngModel', - scope: { config: '=config' }, + scope: { config: '=config'}, link: linkFn }; });