TinyMCE <textarea> two way bound with AngularJS

前端 未结 3 1161
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 23:55

Is it possible to apply two way binding to a that has had TinyMCE applied to it for Rich Text Formatting.

I can\'t get

3条回答
  •  天涯浪人
    2021-01-07 00:26

    Here is my solution using a custom angular directive. You'll need to use jQuery with angularJS, TinyMCE 4 and their jQuery plugin.

    myApp.directive('tinymce', function() {
       return {
          restrict: 'C',
          require: 'ngModel',
          link: function(scope, element, attrs, modelCtrl) {
             element.tinymce({
                setup: function (e) {
                   e.on("change", function() {
                      modelCtrl.$setViewValue(element.val());
                      scope.$apply();
                   }
                }
             });
          }
       }
    }
    

    Then in your HTML:

    
    

    That's it, have fun.

提交回复
热议问题