我该怎么办?
我能够通过使用 textarea
以及与我的模型匹配的 name
属性和带有 ng 的 script
标签将数据导入 CKEditor :bind-template
调用CKEDITOR.replace
。
然后我制作了一个 CKEditor 插件来检测更改并将其写回 textarea
。问题在于,当 CKEditor 初始化并且 CKEditor 不拾取对 textarea
的更改时,textarea
会丢失其事件处理程序。这让我觉得我处理这个问题的方式是错误的。
接下来,我尝试使用 ng:eval-order="LAST" ng:eval="setupCKEditor()"
并通过 setupCKEditor()
函数设置编辑器。这不起作用,因为即使使用 ng:eval-order="LAST"
该函数仍然在创建节点之前运行。
我发现在 CKEDITOR.replace
周围添加 setTimeout(function () {...},0)
会有所帮助。现在唯一的问题是,当它更改模型时,它不会重新绘制屏幕,直到编辑另一个字段。
scope.$root.$eval();
似乎解决了这个问题。
更新
我们最终放弃了这个,因为我们永远无法让它可靠地工作。我们切换到TinyMCE with Angular-UI一段时间,然后最终构建了一些自定义的东西。
How should I go about this?
I was able to get the data into CKEditor by using a textarea
with the name
attribute matching my model and a script
tag with ng:bind-template
to call CKEDITOR.replace
.
I then made a CKEditor plugin that detects changes and writes them back to the textarea
. The problem is that the textarea
looses its event handlers when CKEditor initializes and CKEditor doesn't pickup changes to the textarea
. This makes me think that I am approaching this the wrong way.
Next I tried using ng:eval-order="LAST" ng:eval="setupCKEditor()"
and setting up the editor from the setupCKEditor()
function. This didn't work because even with ng:eval-order="LAST"
the function is still run before the nodes are created.
I have found that adding a setTimeout(function () {...},0)
around the CKEDITOR.replace
helps. Now the only problem is that when it changes the model it doesn't repaint the screen until another field is edited.
scope.$root.$eval();
seems to fix that.
Update
We ended up abandoning this since we could never get it to reliably work. We switched to TinyMCE with Angular-UI for a while and then ended up building something custom.
发布评论
评论(2)
这种方式与 onchange 插件配合使用>http://alfonsoml.blogspot.com/2011/03/onchange-event-for-ckeditor.html。
更新
仅在 v0.10.6 上测试过
This sort of works with the
onchange
plugin from http://alfonsoml.blogspot.com/2011/03/onchange-event-for-ckeditor.html.Update
This has only been tested on v0.10.6
为了完整起见,附加了一个提供角度指令的模块。我还没有使用过它,所以我无法评论它的工作/集成程度。
For completeness, attached is a module to provide an angular directive. I've not used it yet, so I can not comment on how well it works/integrates.