Kamlesh Singh
Kamlesh Singh

Reputation: 11

How do I integrate Tinymce with AngularJS

This is how I have done the coding.

Please I need someones help for this.

Below is the HTML and Javascript code

<html>
[<head>][2]
<script type="text/javascript" src="//cdn.tinymce.com/4/tinymce.min.js"> 
</script>
<script type="text/javascript" 
src='https://cdnjs.cloudflare.com/ajax/libs/angular-ui- 
tinymce/0.0.19/tinymce.js'></script>
<!-- AngularUI TinyMCE -->

</head>
<body ng-app="myApp" ng-controller="myController">
<form>
<textarea ui-tinymce="tinymceOptions" class = "text1" id="mytextarea" 
>Hello, World!</textarea>
</form>
</body>
</html> 

Javascript file:

var myAppModule = angular.module('myApp', ['ui.tinymce']);
myAppModule.controller('myController', function($scope) {
tinyMCE.init({
selector: "text1"
})

$scope.tinymceOptions = {
plugins: 'link image code',
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright | 
code'
};
})

This is what I get after I have run the code

Upvotes: 0

Views: 2694

Answers (1)

omalyutin
omalyutin

Reputation: 454

Please, consider the following code, which should work:

var myAppModule = angular.module('myApp', ['ui.tinymce']);
myAppModule.controller('myController', function ($scope) {
    tinyMCE.init({
        selector: "text1"
    })

    $scope.tinymceOptions = {
        plugins: 'link image code',
        toolbar: 'undo redo | bold italic | alignleft aligncenter alignright | code '
    };

    $scope.model= "text";
})
<html>
<head>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.js"></script>  
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.9.5/tinymce.min.js"></script>
  <script type="text/javascript" src='https://cdnjs.cloudflare.com/ajax/libs/angular-ui-tinymce/0.0.19/tinymce.js'></script>
  <!-- AngularUI TinyMCE -->
  <script type="text/javascript" src="index.js"></script>
</head>

<body ng-app="myApp" ng-controller="myController">
  <form>
    <textarea ui-tinymce="tinymceOptions" class="text1" id="mytextarea" ng-model="model">Hello, World!</textarea>
  </form>
</body>

</html>

Changes, compared to your code:

  1. In HTML I have inserted ng-model, since it is required by tinymce directive. I also initialised the value in JavaScript code by $scope.model= "text";
  2. In head I checked the links and ensure that first AngularJs is loaded (non-minified, so it is possible to see errors, which makes sense), then basic tinymce, then angular-ui-tinymce and finally my code. I have also checked, that all links are not dead.

p.s. Snippet is not working properly. But you can copy code from it and try locally.

Upvotes: 2

Related Questions