How to Add Custom Dropdowns in Quill Editor | Angular 19 TutorialHow to Add Custom Dropdowns in Quill Editor | Angular 19 Tutorial

Hello friends, welcome back to my blog, Today in this blog post, I am going to show you, How to Add Custom Dropdowns in Quill Editor | Angular 19 Tutorial.

Angular Quill Editor

Angular 19+ came and if you are new then you must check below two links:

  1. Angular 19 Basic Tutorials.

Friends now I proceed onwards and here is the working code snippet for quill editor angular, angular 19 quill custom dropdown, rich text editor angular tutorial, quill editor customization, angular 19 tutorial, add dropdown in quill editor, angular quill editor guide, text editor in angular, angular rich text editor, angular 2024 tutorials and use this carefully to avoid the mistakes:

1. Firstly friends we need fresh angular 19 setup and for this we need to run below commands but if you already have angular 19 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

npm install -g @angular/cli

ng new angulareditor

cd angulareditor

ng serve

//Here is the url, you need to run into your browser and see working angular test project
http://localhost:4200/

2. Now friends, here we need to run below commands into our project terminal to install quill editor module into our angular application:

npm install ngx-quill

npm install quill

ng serve --o

3. After done with commands add below code into you angular.json file:

"styles": [
             
            ...
             "node_modules/quill/dist/quill.core.css",
             "node_modules/quill/dist/quill.bubble.css",
             "node_modules/quill/dist/quill.snow.css",
            
           ],
           ...

4. Now guys we need to add code inside app.component.ts file:

import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { QuillModule } from 'ngx-quill'
import { FormsModule } from '@angular/forms';
import Quill from 'quill';

@Component({
    selector: 'app-root',
    imports: [CommonModule, QuillModule, FormsModule],
    templateUrl: './app.component.html',
    styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'angularquill';
  content = '<p>Hello <strong>Quill</strong>!</p>';
  quillInstance: any;

// Quill configuration with all default options + custom dropdown
  quillConfig = {
    toolbar: {
      container: [
        ['bold', 'italic', 'underline', 'strike'],
        ['clean'],
        [{ 'custom-dropdown': ['template1', 'template2'] }] // Our custom dropdown
      ],
      handlers: {
        'custom-dropdown': (value: string) => this.handleCustomDropdown(value)
      }
    }
  };

  onEditorCreated(editor: any) {
    this.quillInstance = editor;
  }

  handleCustomDropdown(value: string) {
    if (!this.quillInstance) return;

    const templates: {[key: string]: string} = {
      template1: '<h1 style="color: #2c3e50;">Header Template</h1>',
      template2: '<footer style="border-top: 1px solid #ccc;">Footer Template</footer>'
    };

    const range = this.quillInstance.getSelection();
    if (range) {
      this.quillInstance.clipboard.dangerouslyPasteHTML(
        range.index,
        templates[value]
      );
    }
  }

}

5. Now guys we need to add code inside app.component.html file:

<quill-editor
  [(ngModel)]="content"
  [modules]="quillConfig"
  (onEditorCreated)="onEditorCreated($event)"
  placeholder="Start typing...">
</quill-editor>

6. Now guys to show the dropdown values we need to add below styles inside styles.css file inside src folder:

 /* Custom dropdown styling */
    .ql-custom-dropdown .ql-picker-label::before {
      content: "Insert Template";
      font-size: 13px;
    }
    .ql-custom-dropdown .ql-picker-item[data-value="template1"]::before {
      content: "Header Template";
    }
    .ql-custom-dropdown .ql-picker-item[data-value="template2"]::before {
      content: "Footer Template";
    }

Guys now run ng serve command to see the output.

Now we are done friends and please run ng serve command and if you have any kind of query then please do comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements. For better understanding must watch video above.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad.

Jassa

Thanks

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.