Integrating Summernote, a Third-Party JavaScript Library, into Angular2

Hello there! I am currently in the process of learning Angular2 and wanted to integrate 3rd party libraries into it. Specifically, I am exploring the use of the summernote Js plugin, which is great for creating rich text areas. You can find more information about it here:

Let's take a look at my my-summernote.component.ts file:

import { ViewChild, ElementRef, AfterViewInit, Component} from '@angular/core';
    import '../../assets/plugins/summernote/summernote.min.js';

    declare var jQuery: any;

    @Component({
        selector: 'my-summernote',
        templateUrl: './my-summernote.template.html'
    })
    export class SummerNoteComponent implements AfterViewInit {
        constructor(){   
        }
        ngAfterViewInit() {        
            jQuery("#theTextArea").summernote();
        }
    }
    

And now let's explore the content of my-summernote.template.html:

<textarea class="form-control" name="theTextArea" id="theTextArea">                              
        </textarea>
    

I have already included jQuery in my index.html file, but unfortunately, I am encountering the following error:

Uncaught Error: Cannot find module "codemirror"
        at webpackMissingModule (main.bundle.js:2211)
        at b.function.Array.reduce.Array.reduce.e (main.bundle.js:2211)
        at Object.505 (main.bundle.js:2211)
    Module not found: Error: Cannot resolve module 'codemirror' in C:\Project\Community3.0\CommunityAng\src\assets\plugins\summernote
    resolve module codemirror in C:\Project\Community3.0\CommunityAng\src\assets\plugins\summernote
    looking for modules in C:\Project\Community3.0\CommunityAng\src
        C:\Project\Community3.0\CommunityAng\src\codemirror doesn't exist (module as directory)
        resolve 'file' codemirror in C:\Project\Community3.0\CommunityAng\src
    resolve file
    

If anyone could provide guidance on what might be causing this issue, I would greatly appreciate it. Thank you!

Answer №1

download bootstrap, summernote, ng2-summernote using npm.

  • locate .angular-cli.json

{

{"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/summernote/dist/summernote.css"
],

"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js",
"../node_modules/summernote/dist/summernote.min.js",
"../node_modules/summernote/dist/lang/summernote-es-ES.min.js"
]}

}

  • include Ng2Summernote in app.module.ts' declarations

    import { Ng2Summernote } from 'ng2-summernote/ng2-summernote';

  • html and js

    <div class="row">
        <div class="col-md-12">
            <ng2-summernote [(ngModel)]="text"></ng2-summernote>
        </div>
    </div>
    <button class="btn btn-primary" (click)="submit()"> Submit</button>
    <div>
        {{model.text}}
    </div>

    import { Component, OnInit } from '@angular/core';
    import { Ng2Summernote } from 'ng2-summernote/ng2-summernote';
    @Component({
      selector: 'app-summernote-richtext',
      templateUrl: './summernote-richtext.component.html',
      styleUrls: ['./summernote-richtext.component.css']
    })
    export class SummernoteRichtextComponent implements OnInit {</p>
    
    <p>constructor() { }</p>
    
    <p>ngOnInit() {
      }
      uploadData:string; 
      text: string = 'appendix';
      data: string = 'appendix';
      model:any = {};
      imgSrc = '/assets/img.jpg'
      options: any = {
          height: 100,
          toolbar: [['style', ['bold', 'italic', 'underline', 'clear']],
          ['para', ['ul', 'ol', 'paragraph']]
          ]
      };
      disabled: boolean = false;
      submit(){
        this.model.text = this.text;
      }
    }
    

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to converting TypeScript classes into functional components in ReactJS

Struggling to convert a typescript class component to functional components and encountering some issues that I can't seem to resolve. Seeking guidance on how to fix this problem. https://i.sstatic.net/QbWwo.png class component import * as React fro ...

Sign up for Observable and receive notifications for specific events

I am working with an Angular service that looks like this: export class EventService { private subject = new Subject<Event>(); send(code: EventCode, data?: any) { this.subject.next(event); } clear() { this.subject.next(); } g ...

Exploring generic types using recursive inference

The scenario: export type SchemaOne<T> = | Entity<T> | SchemaObjectOne<T>; export interface SchemaObjectOne<T> { [key: string]: SchemaOne<T>; } export type SchemaOf<T> = T extends SchemaOne<infer R> ? R : nev ...

Developing an uncomplicated web application using Eclipse, Java, Gradle, Wildfly, Hibernate JPA, Spring, and Angular

In my journey of creating web applications using Eclipse, Java 11, Wildfly 17, and various technologies like Hibernate and JSFs with Primefaces, I've reached a point where everything works well together. However, I am now looking to take it a step fur ...

Issues encountered while attempting to use 'npm install' on Angular, leading to

Having trouble with npm i in my project. It's not working for me, but others can install it smoothly. I've checked all the node and angular versions, but I can't figure out what's missing. Could it be my laptop's compatibility? Ple ...

Deducing the return type of asynchronously generated functions

My expectation is to automatically determine the return type of async functions when they are yielded as values from a generator. In the following example, the inference of the type of the yielded async functions appears to work correctly (detected as () ...

What is the best way to prevent TSC from including the node_modules folder in my compilation

I have encountered a persistent issue that all previous solutions have failed to address. Here is the snippet from my tsconfig file that I believe should resolve the problem: ... "compilerOptions": { "skipLibCheck": true, ... &quo ...

Ensure that TypeScript compiled files are set to read-only mode

There is a suggestion on GitHub to implement a feature in tsc that would mark compiled files as readonly. However, it has been deemed not feasible and will not be pursued. As someone who tends to accidentally modify compiled files instead of the source fil ...

What is the best method for custom Validators to access specific Values on a Form?

Seeking guidance on implementing custom validation in my Angular app. Specifically, I need to validate an email address input against a local array called emails. The challenge is that the emails data comes from an API call and is initially empty when the ...

Troubleshooting the ERR_CONNECTION_RESET issue when uploading large files on Angular 7 with Node JS and IIS, using pm2 for

Can you assist me? I am encountering a problem where the connection gets reset and an error message ERR_CONNECTION_RESET appears when trying to upload large files (150+MB) to the server. This issue only occurs when interacting with the public API, everythi ...

Establishing navigation routes in a nested Angular 2 module through an NPM package

Currently, I am in the process of constructing an Angular 2 application and have established the following basic structure: AppModule AppComponent App.Routing App.template App.module In addition to this setup, I have ...

Unlock the key to connecting the output of one observable to another in rxjs

I have a procedure for saving users in the database. These are the steps I take: 1) First, I validate the request. 2) Next, I hash the password. 3) Finally, I store the user details in the users collection along with the hashed password. Below is the ...

Creating a flexible parent tag for grouping child elements using Angular 2

My Objective I am determined to develop an Angular 2 button component that can dynamically render as either an <a /> tag or an <input /> tag based on the value of a property called type. Furthermore, this button component should be able to acc ...

Unique validation for mandatory selection on changeSelected

In my Angular HTML code, I have set up a dropdown and two text-boxes. My goal is to create a feature where, if the user selects an option from the 'payable_frequency' dropdown, then either one of the 'payable_commission' fields (min or ...

Updating Angular components by consolidating multiple inputs and outputs into a unified configuration object

When I develop components, they often begin with numerous @Input and @Output properties. However, as I continue to add more properties, I find it beneficial to transition to utilizing a single config object as the input. For instance, consider a component ...

Styling CardViews in Nativescript

For some reason, the CardView is not displaying the border and shadow properly. Instead, it just shows a long line. https://i.sstatic.net/p8YQc.jpg Below is the code that I have been experimenting with in Nativescript for Angular: <StackLayout> < ...

Neglecting to validate types in the personalized response format within Express

I'm new to typescript and I've run into a problem where I can't seem to get my types validated. Route app.use((req: Request, res: Response) => { // here 404 is a string but should be a number according to type defined but no error is s ...

Guide on loading HTML templates into tab content within an Angular application

I am currently working on a project using Angular 8. After reading an informative article, I gained an understanding of concepts like ContentChildern, QueryList, and successfully built a sample tabs component. Here is the link to the article for reference ...

Having trouble locating module '@angular/http'?

In the configuration file systemjs.config.js for my Angular 2 application, I included the following entry in the map object: '@angular/http': 'https://npmcdn.com/@angular/http' While trying to import '@angular/http' at the b ...

Determine the consistent type for numerous properties

Is it feasible to have Typescript automatically infer the type of multiple properties to be the same, or even infer the types based on a specific property? For example, consider the following code snippet -> interface Test<T> { value1: T; val ...