How to use summernote with angularjs

2019-02-09 07:04发布

问题:

I would use summernote with AngularJS. I have found https://github.com/outsideris/angular-summernote, but this doesn't work for me. The only thing I get is an Error

Error: undefined is not a function (evaluating 'element.summernote(summernoteConfig)')

I have included all required files like jquery, bootstrap, summernote, etc.

My second idea was to use summer note without the angular-summernote directive. But also that shouldn't work perfectly.

If I try

$(document).ready(function() {
  $('.summernote').summernote();
});

summernote doesn't work, but If I try sth. like

$.getScript('//cdnjs.cloudflare.com/ajax/libs/summernote/0.5.1/summernote.min.js',function(){
  $('#summernote').summernote();
});

it works, but I would use my local copy of summernote so the second one isn't that what I need

Hope you understood my problem and thanks for any help Rico

回答1:

Ok guys, I've found the problem, for everyone with the same problem it's a very stupid mistake ;)

The problem was the I include the main angular.min.js file before jQuery an Bootstrap. Now I include jQuery first, then Bootstrap and then AngularJS and it works perfect.

<link rel="stylesheet" type="text/css" href="bootstrap.css" />
<link rel="stylesheet" type="text/css" href="summernote.css" />
<script src="jquery-2.1.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="summernote.min.js"></script>
<script src="angular.min.js"></script>
<script src="angular-summernote.min.js"></script>

In this order it works perfect for me.

A short tip, if you have also a problem with the button size, only thing to do is include <!DOCTYPE html> in you're main html file.

Rico



回答2:

We have similar issue, the only workaround we see if to wrap it with it's own module (in the following it's summernoteDemo) like:

...
            <div class="span1">
                <div ng-app="summernoteDemo">
                    <summernote id="editor" code="text" ng-model="item.description"></summernote>
                    <br>
                    <textarea type="text" ng-model="item.description" style="width:100%;"></textarea></br>
                </div>

But we have issue to make it appear in more than one place/instance. Maybe you can try and let us know.