Search code examples
angularjstinymcetinymce-3

Binding value into TinyMCE <textarea> using AngularJS model


I am developing an ASP.net MVC application with AngularJS and TinyMCE.

I need to display a WYSIWYG textarea to the user to get input.

I am not able to bind initial value into the textarea. Need help. The following is what I have done.

<script type="text/javascript">
    tinyMCE.init({
        mode: "textareas",
        theme: "advanced",
        theme_advanced_path: false,
        theme_advanced_buttons1: "fontselect,|,bold,italic,underline,|,fontsizeselect,|,forecolor,backcolor",
        theme_advanced_buttons2: "|,justifyleft,justifycenter,justifyright,|,link,unlink,|,bullist,numlist,|,code",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: true,
    });
</script>

View:

<textarea data-ng-model="selectedProduct.ProductText">
  {{selectedProduct.ProductText}}
</textarea>

Solution

  • You definitely want to use this library: https://github.com/angular-ui/ui-tinymce Things get much easier then. A sample:

    <textarea ui-tinymce="tinymceOptions" ng-model="tinymceModel"></textarea>
    
    myAppModule.controller('MyController', function($scope) {
        $scope.tinymceOptions = {
                //enter any options here
            }
        };
    });