angular-ui / ui-tinymce

AngularUI wrapper for TinyMCE
MIT License
488 stars 371 forks source link

Question: Is it possible to dynamically generate the options of the editor? #192

Closed nicolasgarnil closed 8 years ago

nicolasgarnil commented 8 years ago

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. As a consequence of this, the options are not passed to the directive.

<textarea ui-tinymce="tinymceOptions" ng-model="email.body"></textarea>
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.

I a have little experience in angular directives, is it possible to watch changes in the options and reflect them in the editor? It would be a great feature of this directive.

deeg commented 8 years ago

This is related to issue #158.

In order to not initialize TinyMCE until the options are defined add an ng-if check to the text area:

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

I am going to close this ticket in favor of #158 for now. I will open a new bug about the refresh event not removing the old editor, as I have seen that too.

In the future please ask any questions you may have using the angular-ui-tinymce tag on StackOverflow.

If you have reproducible bugs, continue opening issues attaching a Plunker describing the issue.

nicolasgarnil commented 8 years ago

That workaround doesn't works when you need to re-initialise the editor more than one time. After the options are defined you can no longer re-initialise the editor. In my example, the template can be changed more than once.

deeg commented 8 years ago

That makes sense. I am hoping this will get fixed by the other bugs open.

I do agree that when the options change the editor should re-initalize, so I hope to get that feature in there.

In the mean time, we welcome all pull requests if you have any time to implement the feature.