Giter Club home page Giter Club logo

ngx-summernote's Introduction

NgxSummernote

Summernote editor for Angular 😎

Installation

Install ngx-summernote and dependencies:

npm install --save ngx-summernote summernote jquery

Compatibility:

Angular ngx-summernote
> 14 1.0.0 (Ivy support)
> 14 0.9.0
13 0.8.8
12 0.8.5
11 0.8.4
10 0.8.x
9 0.7.x
8 0.7.x
7 0.6.x
6 0.5.4

Editor

Add JQuery and Summernote scripts and styles to the angular.json file:

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

Add NgxSummernoteModule to the app.module.ts file OR to the subcomponent module.ts file if using lazy loading:

...
import { NgxSummernoteModule } from 'ngx-summernote';
...
@NgModule({
...
  imports: [
    ...
    NgxSummernoteModule
    ...
  ]
})
export class AppModule { }

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

<div [ngxSummernote]></div>

You may also configure Summernote with your own config:

<div [ngxSummernote]="config"></div>
export class AppComponent implements OnInit {
  ...
  config = {
    placeholder: '',
    tabsize: 2,
    height: '200px',
    uploadImagePath: '/api/upload',
    toolbar: [
        ['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']
  }
  ...
}

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

If you want to upload images to server and use remote paths in editor, you need to set 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.

To remove images from server when deleted from HTML, use (mediaDelete):

<div [ngxSummernote] (mediaDelete)="onDelete($event)"></div>
onDelete(file) {
  deleteResource(file.url);
}

Add custom button

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

function customButton(context) {
  const ui = $.summernote.ui;
  const button = ui.button({
    contents: '<i class="note-icon-magic"></i> Hello',
    tooltip: 'Custom button',
    container: '.note-editor',
    className: 'note-btn',
    click: function() {
      context.invoke('editor.insertText', 'Hello from test btn!!!');
    }
  });
  return button.render();
}

export class AppComponent implements OnInit {
  config: any = {
    ...
    buttons: {
      'testBtn': customButton
    }
  };
  ...
}

See detailed info on custom buttons here.

Development

To use the test application, first build the lib:

ng build ngx-summernote

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

npm start

Contributors

ngx-summernote's People

Contributors

dependabot[bot] avatar hupf avatar indianazhao avatar ishan123456789 avatar jmannau avatar llulani avatar lonerzzz avatar luigiellebalotta avatar lula avatar minchopm avatar nickshcherba avatar tim-boerner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ngx-summernote's Issues

blur event

Send blur event from summernote and mark the control as touched.

Invoke summernote function

Hi,

I need to invoke summernote function Like $('#summernote').summernote('editor.insertText', 'This text should appear at the cursor');

any option for this ?

I need to insert text at current cursor position , so
Ref. Link - summernote/summernote#282

Thanks
kamlesh

2 way binding not working or how do I get the inner Html

I have the editor loaded and the initial content loaded using the summernoteModel:

In component ts:
private wysiwygContent: string;
this.wysiwygContent = '<p>Testing....</p>';

In template:
<div [ngxSummernote]="wysiwygConfig" [summernoteModel]="wysiwygContent"></div>
testing 2 way binding:
<div>{{wysiwygContent}}</div>

However as the content is edited there is no 2 way binding between the summernoteModel and my property wysiwygContent. Is this supported and if so how?
If not how do I get the updated content and manually update the property wysiwygContent, preferably without using jQuery and accessing summernote directly.

I am using the config:
this.wysiwygConfig = { toolbar: [ ['style', ['bold', 'italic', 'underline', 'clear']], ['font', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']], ['fontsize', ['fontname', 'fontsize', 'color']], ['para', ['style0', 'ul', 'ol', 'paragraph', 'height']], ['insert', ['table', 'link', 'hr']], ['misc', ['undo', 'redo', 'codeview']] ] };

Thanks.

Undo removes initial text

Buttton undo removes initial text.

My .html file:

<div [formGroup]="fg">
  <div formControlName='editorText' [ngxSummernote]="configEditor"></div>
</div>

My .ts file:

...
editorControl: FormControl = new FormControl('test');

  constructor(fb: FormBuilder) {
    this.fg = fb.group({
      editorText: this.editorControl
    });
  }

  configEditor = {
    tabsize: 2,
    height: 600,
    toolbar: [
      ['misc', ['undo', 'redo']],
      ['font', ['bold', 'italic', 'underline', 'strikethrough', 'clear']],
      ['para', ['style0', 'ul', 'ol', 'paragraph']]
    ],
  };
...

Is there a way how to solve that ?

TS2339: Property 'summernote' does not exist on type 'JQueryStatic'.

I'm trying to create a custom button.
I use the summernote exemple

var HelloButton = function (context) {
      var ui = $.summernote.ui;

      // create button
      var button = ui.button({
        contents: '<i class="fa fa-child"/> Hello',
        tooltip: 'hello',
        click: function () {
          // invoke insertText method with 'hello' on editor module.
          context.invoke('editor.insertText', 'hello');
        }
      });

      return button.render();   // return button as jquery object
    }

But I have got this error
TS2339: Property 'summernote' does not exist on type 'JQueryStatic'.

On Init Mark dirty on true

On start the binding the form control has marked dirty on true.

<div [ngxSummernote]="summerNoteConfig" [formControl]="inputControl"></div>

And the validations are displayed.

The dirty atribute only be mark on start use the component.

Chears..

Drag & drop

Hi,
I am dropping a select text (such as a word) in the middle of the content but it always drops and appears at the start position.

Please see attached picture. I was selecting and dragging the word 'Manager' in the box [ ] but once I drop it, it always appears at the start of the content.

Please let me know if there is a way to drag drop (a word or text) at a specific location in the content.

Thanks

summernote-sali

Disable/ReadOnly ngxSummernote in Angular 7

Hi,

I am trying to disable ngxSummernote which i am using under Angular 7 but somehow its not disabling the content inside summer note.

code:-
<input [disabled]="role=='R'" name ="modelContainerLabels" [ngxSummernote]="config" [(ngModel)]="labelingReviewInfo.modelContainerLabels">

i am trying [disabled]="role=='R'"

This is not working, do we have any other alternative??

Thanks
Ramit

how can i get the value from the component?

I can't get the value, in angular form the code is:

this.myForm.value.name

I try this:
<div [ngxSummernoteView]="content" #summer formControlName="sumer" ></div>

With angular forms:
this.myForm.value.name

With ViewChild
this.summer.nativeElement.value

also with innerHTML

but for the summernote component what is the way?

thanks

How can i use dialogsInBody option?

I can't use ngx-summernote in mat-tab. Because mat-tab.active class has "position:relative" style.
Can i use dialogsInBody property or do you have another solution?

Screen Shot 2019-08-11 at 02 30 49

when form is in edit mode

when form is in edit mode text box focus loose with summernote ,
when we click on text box its loses focus,
every time foucus goes to summernote editor

Double caret icons on the dropdown menu

Dear Team,

I've integrated summernote in my website using Angular 7 but at the dropdown menus in the toolbar two caret icons are showing.

dropdown

Any ideas? Thanks.

ERROR TypeError: _this._$element.summernote is not a function

I have error ERROR TypeError: _this._$element.summernote is not a function in

Installation
Install ngx-summernote and dependencies:

npm install --save summernote ngx-summernote

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>

Does this work (or can it work) with ng-bootstrap?

Hi, wondering if this works with ng-bootstrap as it provides angular directives for bootstrap. I tried loading the summernote-bs4 css/js but it seems as though it only supports vanillar bootstrap. Wondering if ng-summernote has a bridge I'm missing in the docs to support it?

UI bugs in module

The following features are not working:

  • Color selection - Reset to default

  • 'Bold','Italic','Underline' in the toolbar doesn't appear to be enabled after the user clicked on them

Editor not working (Nothing is shown)

Team,

I am trying an integration of summernote using Angular 7. Despite the fact that there is no error in the console, the editor is not displayed.

app.module.ts

`....
import { NgxSummernoteModule} from "ngx-summernote";
...

@NgModule({
imports: [
...
NgxSummernoteModule,
],
...
})
`

app.component.html
<div [ngxSummernote]></div>

Did I miss anything?

Thanks.

L

Use summernote() function

Hello,

i want to use the summernote() function to reset my textarea :

$('#summernote').summernote('reset');

I've tried with ViewChild, does not work, same for jQuery manner..

Do you know how to do this ?

Thanks you,
Dylan

Not working with Angular 7.0.6

Hi,

Initially i have tried cloning your repo with my git and found issue in pasting images after integrating with my application.

Then i created new fresh application by ng new and followed all your steps which was mentioned.
Found the same issue, its not allowing pictures to be pasted through clipboard.

I am using Angular 7.0.6. Seems some additional steps we need to do in order to make it work. Its working better when i clone repo and use it as standalone because that time it uses inbuilt CLI.

The moment i integrate with higher version its not allowing pictures to be pasted.

Please let me know your suggestion and experience to resolve this. I would highly appreciate.

Thanks
Ramit

Summernote not allowing me to paste images

Hi,

I have integrated this summernote in my Angular 7 application. It integrated smoothly but its not allowing me to paste images which i am using snipping tool of windows. Any suggestion, please help!

Thanks
Ramit

Editor not initialized when initializing listeners, if immediateAngularModelUpdate = true option is used

The problem occures when using immediateAngularModelUpdate = true in initialization array. While debugging, I found out that you are trying to bind keyup event on _editor, which at this time is not initialized:

if (this._options.immediateAngularModelUpdate) {
this._editor.on('keyup', function () {
setTimeout(function () {
self.updateModel();
}, 0);
});
}

To fix this issue, please inverse the following lines (this.zone.runOutsideAngular with this.initListeners):

this.initListeners();
// init editor
this.zone.runOutsideAngular(() => {
this._editor = this._$element.summernote(this._options).data('summernote').$note;
if (this.ngxSummernoteDisabled) {
this._$element.summernote('disable');
}
});

İmage Upload With Header(image upload with jwt bearer token)

Im using jwt-bearer auth on my project that using asp.net core Rest Api and Angular .Instead of using base64 images,i want to upload images to my own server .But i need to send image with header that contains token information.I tried to use uploadImagePath but it gives 401 Unauthorized.Is there a way to upload image with header ?

Upload Image To .Net Core API

Hi

I want to store image uploaded from summernote into a .net core api, but I get this error

er

The image uploaded successfully and the address is ok.

Component and summernote config:

config

Html Code:

summernote

.net core Api action

api

Anuglar version 7

Asp.Net Core 2.1

I used CkEditor 4 in another project this way and it was okey, image uploaded in rootpath of API accessable with Angular. I don't know why its giving me Not Fount error with Summernote...!

how can i retrieve saved images into byteArray?

Hi,

How can i retrieve saved images using summernote into byte Array.

My images are getting saving into DB like below
e.g. :-


I am also attaching the string generated after pasting image into summer note and my db

On retrieval I want those to be converted into byte-array.
Any help would be appreciated!
sampleTestImage.txt

Thanks
Ramit

Upload multiple images unavailable

When multiple images are selected, only the first one can be uploaded.
Problematic code:
private async uploadImage(files) { const data = new FormData(); this.imageUpload.emit({ uploading: true }); data.append('image', files[0]); if (this._options.uploadImagePath) { this.http.post(this._options.uploadImagePath, data) .pipe( map((response: { path: string }) => response && typeof response.path === 'string' && response.path), catchError(e => { throwError('An error occured while uploading' + e); return of(''); })) .subscribe(dataIn => { if (dataIn) { this._$element.summernote('insertImage', dataIn); this.imageUpload.emit({ uploading: false }); } else { this.insertFromDataURL(files); } }, (e) => { this.insertFromDataURL(files); }); } else { this.insertFromDataURL(files); } }

get code

I need to get the html code from the editor, but the code is breaking some special characters like for example "á" or "õ".

<textarea id="summernote-textarea" [ngxSummernote] [(summernoteModel)]="template"></textarea>

Uploade and show image in Angular 8??

I'm using summernote editor in my angular 8 project. Its working fine.
But Images are uploading and showing in base64.

How can i use upload image and use nxgSummernoteView innerHTML to show images in content.
Contents are blog post.

Please help..

How to access native object.

Hello.

Is there a way to access native object like "ViewChild" ?

E.g,
(ViewChild object).nativeElement.function();

Spelling mistake in documentation

Hi,

I beilive that there is a spelling mistake in documentation
... ['para', ['style0', 'ul', 'ol', 'paragraph', 'height']], ...

Probably, there should be style instead of style0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.