angularjs - 如何使用包裹在 CKEditor 小部件中的 Angular 指令

标签 angularjs widget ckeditor directive

我们使用 Angular 指令将数据渲染到项目的 CKEditor 中。我创建了使用该指令作为模板的小部件,但它不会将任何内容渲染到该字段中。请帮忙!
先感谢您!

小部件来源:

CKEDITOR.plugins.add('grid', {
requires: 'widget',
init: function(editor) {

    editor.widgets.add('grid', {
        template: '<div class="widget"> <div table-Directive></div> </div>',
        upcast: function(element) {
            return (element.name == 'div' && element.hasClass('widget'));
        },
        allowedContent: 'div[*]'
    });

    editor.ui.addButton('grid', {
        label: 'Demo',
        command: 'grid',
    });
}

});

指令来源:
define(['angular','js/controller/table-controller'],
  function(angular) {
  'use strict';

  angular
   .module('todoApp.table-directive', ['todoApp.table-controller'])
   .directive('tableDirective', [tableDirective]);

 function tableDirective() {
   var directive = {
     controller: 'TableController',
     templateUrl: 'template/tableDirective.html',
   };
   return directive;
 }
});

编辑:
其实你可以在ckeditor里面使用angular组件,你只需要自己用$compile编译它。
在这里我附上简单的代码说明
// temporarily remove data-widget attribute sets by CKEditor before $compile()
// because angular thinks that data-widget is the same directive as widget
// and applies the directive twice
var dataWidget = element.getAttribute('data-widget');
element.removeAttribute('data-widget');
// use the scope of the closest parent that has a scope
var editorScope = $(editor.container.$).closest('.idoc-editor').isolateScope();
var compiledElement = application.$compile(element)(editorScope);
// $compile replaces the compiled element (instead of only decorating it)
// and this breaks the base CKEditor widget (this.element doesn't point to the
// correct element after $compile
this.element = new CKEDITOR.dom.node(compiledElement[0]);
this.element.$.setAttribute('data-widget', dataWidget);

最佳答案

我认为您不能在 ckeditor 中插入 angular js 代码,ckeditor 是在 iframe 中执行的,而 angular 脚本未在此 iframe 中加载。

但是在 ckeditor 小部件中,您可以使用 ajax 请求与您的服务器进行交互

关于angularjs - 如何使用包裹在 CKEditor 小部件中的 Angular 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29021193/

相关文章:

angularjs - 根据 ui-grid 中的 cellTemplate 设置 csv 导出格式

javascript - html5视频结束时调用AngularJS Controller 函数

angularjs - 路由更改时不会触发 routeChangeStart

linux - 如何使用 Ada 代码关闭图形窗口/小部件?

javascript - CKEditor 4 为链接添加新属性

javascript - 在启用 js 的情况下运行 capybara 测试时不呈现 CKEditor

javascript - AngularJS:在 <li></li> 上使用 ng-repeat 并调用 ng-click 的不同函数?

ios - 在 Today Extensions (iOS 8) 上保存和加载数据

python - 你能组合两个 tkinter tk 小部件吗?

windows - ckeditor对话框定位