Link in Angular Rich Text Editor Component
16 Jan 20255 minutes to read
A hyperlink can be insert into the editor for quick access to the related information. The hyperlink itself can be a text or an image.
Inserting a Link
To insert a hyperlink:
- Position your cursor where you want to insert the link, or select the text or image you wish to convert into a hyperlink.
- Click the “Insert HyperLink” tool on the toolbar.
- In the Insert Link Dialog that appears, fill in the following options.
To use use image and link tool, configure
ImageService, LinkService
in the provider section.
Options | Description |
---|---|
Web Address | Enter or paste the destination URL for your link |
Display Text | Enter or edit the required text that you want to display text for the link |
Tooltip | To display additional helpful information when you place the pointer on the hyperlink, type the required text in the “Tooltip” field. |
Open Link in New Window | Specify whether, the given link will be open in new window or not |
import { Component } from '@angular/core';
import { RichTextEditorModule, ToolbarService, LinkService, ImageService, HtmlEditorService, QuickToolbarService, TableService, PasteCleanupService } from '@syncfusion/ej2-angular-richtexteditor';
@Component({
imports: [
RichTextEditorModule
],
standalone: true,
selector: 'app-root',
template: `<ejs-richtexteditor id='editor' [toolbarSettings]='tools'></ejs-richtexteditor>`,
providers: [ToolbarService, LinkService, ImageService, HtmlEditorService, QuickToolbarService, TableService, PasteCleanupService]
})
export class AppComponent {
public tools = {
items: ['Image', 'CreateLink']
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
The Rich Text Editor validates URLs as you type in the Web Address field. Invalid URLs will be highlighted in red when you click the insert button in the
Insert Link
dialog.
Removing a Link
To remove a hyperlink:
- Select the linked text or image.
- Click the “Remove Hyperlink” tool in the toolbar.
This action will remove the hyperlink while keeping the original text or image intact.
Auto Link Generation
The Rich Text Editor supports automatic link generation. When you type a URL and press Space or Enter, the editor automatically converts the typed URL into a clickable hyperlink.
Customizing the Link Quick Toolbar
The Rich Text Editor allows you to customize the tools in the link quick toolbar. You can add or remove items by using the quickToolbarSettings
property.
The quick toolbar for the Link has the following options.
Tools | Description |
---|---|
Open | Opens the linked page in a new window. |
Edit Link | Allows you to edit the selected link. |
Remove Link | Removes the link from the selected content. |
Custom Tool | Adds custom options to the quick toolbar. |
The following example demonstrates how to customize the link quick toolbar using the quickToolbarSettings
property.
import { Component } from '@angular/core';
import { RichTextEditorModule, ToolbarService, LinkService, ImageService, HtmlEditorService, QuickToolbarService, TableService, PasteCleanupService, QuickToolbarSettingsModel } from '@syncfusion/ej2-angular-richtexteditor';
@Component({
imports: [
RichTextEditorModule
],
standalone: true,
selector: 'app-root',
template: `<ejs-richtexteditor id='editor' [toolbarSettings]='tools' [quickToolbarSettings]='quickToolbarSettings'></ejs-richtexteditor>`,
providers: [ToolbarService, LinkService, ImageService, HtmlEditorService, QuickToolbarService, TableService, PasteCleanupService]
})
export class AppComponent {
public tools = {
items: ['Image', 'CreateLink']
};
quickToolbarSettings: QuickToolbarSettingsModel = {
link: ['Open', 'Edit', 'UnLink', 'FontColor']
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));