简体   繁体   English

是否可以动态生成angular-ui tinymce编辑器的选项?

[英]Is it possible to dynamically generate the options of the angular-ui tinymce editor?

I am using tinymce editor through the ui-tinymce Angular directive. 我正在通过ui-tinymce Angular指令使用tinymce编辑器。

<textarea ui-tinymce="tinymceOptions" ng-model="email.body"></textarea>

I can't initialise the editor with the content_css option set to a value which is obtained from an XHR request because the link function of the directive is called before the callback of the XHR request. 我无法将content_css选项设置为从XHR请求获得的值来初始化编辑器,因为在XHR请求的回调之前调用了指令的link函数。 As a consequence of this, the options are not passed to the directive. 因此,选项不会传递给指令。

Template.get({ id: $routeParams.id }, function(response) {
  $scope.template = response.attributes;

  $scope.tinymceOptions = {
      inline: false,
      plugins : 'code importcss preview code',
      skin: 'lightgray',
      theme : 'modern',
      content_css: $scope.template.content_css
    };
});

If I broadcast a $tinymce:refresh event after initialising the options, the editor gets re-initialised with the new options, but the old editor is not removed. 如果在初始化选项后广播$tinymce:refresh事件,则将使用新选项重新初始化编辑器,但不会删除旧的编辑器。

I a have little experience in angular directives, is it possible to watch changes in the options and reflect them in the editor? 我在角度指令方面经验很少,是否可以观察选项中的更改并将其反映在编辑器中?

You can wait for the options you load asynchronously and display the editor only after you got them. 您可以等待异步加载的选项,并仅在获得它们后才显示编辑器。 Proof of concept: 概念证明:

View: 视图:

<div ng-controller="MyCtrl">
    <div ng-if="!tinymceOptions">Please wait, we're initliazing editor for you!</div>
    <div ng-if="tinymceOptions">
        <textarea ui-tinymce="tinymceOptions" ng-model="email.body"></textarea>
    </div>
</div>

And controller: 和控制器:

module.controller('MyCtrl', function($scope) {
    Template.get({ id: $routeParams.id }, function(response) {
        // your code here
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM