1.0.0 • Published 11 months ago

ngx-summernote v1.0.0

Weekly downloads
3,558
License
MIT
Repository
github
Last release
11 months ago

NgxSummernote

Summernote wysiwyg editor for Angular.

This project was generated with Angular CLI version 6.0.0.

projects contains ngx-summernote lib (see Angular CLI libraries generation).

src contains an example application. Run ng serve to test.

Installation

Install ngx-summernote and dependencies:

npm install --save ngx-summernote summernote jquery

Compatibility:

Angularngx-summernote
80.7.x
70.6.x
60.5.4

Editor

Add add JQuery and Summernote scripts and styles in angular.json file:

"styles": [
  ...
  "node_modules/summernote/dist/summernote-lite.css"
],
"scripts": [
  ...
  "node_modules/jquery/dist/jquery.min.js",
  "node_modules/summernote/dist/summernote-lite.js"
]

Use [ngxSummernote] directive on an element to init Summernote editor:

<div [ngxSummernote]></div>

Summernote is initialized with the following deafult config:

{
  placeholder: '',
  tabsize: 2,
  height: 100,
  uploadImagePath: '',
  toolbar: [
      // [groupName, [list of button]]
      ['misc', ['codeview', 'undo', 'redo']],
      ['style', ['bold', 'italic', 'underline', 'clear']],
      ['font', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
      ['fontsize', ['fontname', 'fontsize', 'color']],
      ['para', ['style', 'ul', 'ol', 'paragraph', 'height']],
      ['insert', ['table', 'picture', 'link', 'video', 'hr']]
  ],
  fontNames: ['Helvetica', 'Arial', 'Arial Black', 'Comic Sans MS', 'Courier New', 'Roboto', 'Times']
}

You may also configure Summernote with your own summernote config:

<div [ngxSummernote]="config"></div>

The provided config will be merged with the default one.

See Summernote available initialization options here.

Viewer

Use [ngxSummernoteView] directive on an element to set innerHTML of an element:

<div [ngxSummernoteView]="content"></div>

Upload images to server instead of inserting Base64 in HTML

Use uploadImagePath option in config:

config = {
  uploadImagePath: 'http://example.com/upload' // API URL to upload image
};

API call response is expected to be like:

{
  path: 'the path of the image' // http://example.com/image-path.png
}

If the reponse does not follow the above structure then the image is inserted as data URL.

Add custom button

In your component setup summernote config and code for the custom button, e.g.:

config: any = {
    height: '200px',
    uploadImagePath: '/api/upload',
    toolbar: [
      ['misc', ['codeview', 'undo', 'redo', 'codeBlock']],
      ['font', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
      ['fontsize', ['fontname', 'fontsize', 'color']],
      ['para', ['style0', 'ul', 'ol', 'paragraph', 'height']],
      ['insert', ['table', 'picture', 'link', 'video', 'hr']],
      ['customButtons', ['testBtn']]
    ],
    buttons: {
      'testBtn': this.customButton()
    }
  };

  ...

  customButton() {
    return (context) => {
      const ui = $.summernote.ui;
      const button = ui.button({
        contents: 'Test btn',
        tooltip: 'Test',
        click: function () {
          context.invoke('editor.pasteHTML', '<div>Hello from test btn!!!!</div>');
        }
      });
      return button.render();
    }
  }

Development

To use the test application, first build the lib:

npm run build_lib

Then serve the test application and open it in your browser:

npm start
1.0.0

11 months ago

0.9.1

11 months ago

0.8.9

1 year ago

0.9.0

1 year ago

0.8.8

2 years ago

0.8.5

3 years ago

0.8.7

3 years ago

0.8.6

3 years ago

0.8.4

3 years ago

0.8.1

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.0

4 years ago

0.7.8

4 years ago

0.7.7

4 years ago

0.7.7-beta1

4 years ago

0.7.7-beta2

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.5-beta4

4 years ago

0.7.5-beta3

4 years ago

0.7.5-beta2

4 years ago

0.7.5-beta1

4 years ago

0.7.4

4 years ago

0.7.2

4 years ago

0.7.3

4 years ago

0.7.1

4 years ago

0.7.0

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago