Open In App

Angular PrimeNG Form Editor Templates

Last Updated : 05 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Angular PrimeNG Form Editor Templates.

The Form Editor is a Quill-based rich text editor component. Angular PrimeNG Form Editor Templates are used to put some content on some pre-structured containers. Editor templates are discussed below: 

  • header: This is used to create the header/toolbar of the Editor.

Syntax:

<p-editor >
    <ng-template pTemplate="header">
          ...
    </ng-template>
</p-editor>

 

Creating Angular application & module installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

 

Example 1: In this example, we will create a Form Editor header template using Bold, Italic, Strike, Clean, Image, and Link editing options.

app.component.html

HTML




<head>
    <link href=
        rel="stylesheet">
</head>
  
<div style="width: 50%;">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
  
    <h2>
        Angular PrimeNG Form Editor 
        Templates Component
    </h2>
      
    <p-editor [style]="{ height: '250px' }">
        <ng-template pTemplate="header">
            <span class="ql-formats">
                <button type="button" 
                    class="ql-bold" 
                    aria-label="Bold">
                </button>
                <button type="button" 
                    class="ql-italic" 
                    aria-label="Italic">
                </button>
                <button type="button" 
                    class="ql-underline" 
                    aria-label="Underline">
                </button>
                <button type="button" 
                    class="ql-clean" 
                    aria-label="clean">
                </button>
                <button type="button" 
                    class="ql-image" 
                    aria-label="Image">
                </button>
                <button type="button" 
                    class="ql-link" 
                    aria-label="Link">
                </button>
            </span>
        </ng-template>
    </p-editor>
</div>


app.component.ts

Javascript




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
  
export class AppComponent { }


app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { EditorModule } from 'primeng/editor';
import { AppComponent } from './app.component';
import { InputMaskModule } from 'primeng/inputmask';
  
@NgModule({
    imports: [
        EditorModule,
        BrowserModule,
        BrowserAnimationsModule,
        InputMaskModule,
        FormsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

Example 2: In this example, we will create a Form Editor header template using Bold, Italic, Underline, Strike, blockquote, and code-block editing options.

app.component.html

HTML




<head>
    <link href=
        rel="stylesheet">
</head>
<div style="width: 50%;">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
  
    <h2>
        Angular PrimeNG Form 
        Editor Templates Component
    </h2>
      
    <p-editor [style]="{ height: '150px' }">
        <ng-template pTemplate="header">
            <span class="ql-formats">
                <button type="button" 
                    class="ql-bold" 
                    aria-label="Bold">
                </button>
                <button type="button" 
                    class="ql-italic"
                    aria-label="Italic">
                </button>
                <button type="button" 
                    class="ql-underline" 
                    aria-label="Underline">
                </button>
                <button type="button" 
                    class="ql-strike" 
                    aria-label="strike">
                </button>
                <button type="button" 
                    class="ql-blockquote" 
                    aria-label="blockquote">
                </button>
                <button type="button" 
                    class="ql-code-block" 
                    aria-label="code-block">
                </button>
            </span>
        </ng-template>
    </p-editor>
</div>


app.component.ts

Javascript




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent { }


app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { EditorModule } from 'primeng/editor';
import { AppComponent } from './app.component';
import { InputMaskModule } from 'primeng/inputmask';
  
@NgModule({
    imports: [
        EditorModule,
        BrowserModule,
        BrowserAnimationsModule,
        InputMaskModule,
        FormsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

Reference: https://primefaces.org/primeng/editor



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads