This file provides documentation for the HugeRTE Angular integration package.
Add the HugeRTE Angular integration to your project using npm (or an npm-based package manager like yarn or pnpm):
npm install @hugerte/hugerte-angular
or:
yarn add @hugerte/hugerte-angular
or:
pnpm add @hugerte/hugerte-angular
The HugeRTE Angular integration package exports an EditorModule
and an EditorComponent
. Use the module in your module or the component in your component, whether approach better fits your needs. Add the one you decided to use to the imports
array of your module or component, respectively.
Then, you can use <editor></editor>
iin your template. The following options are available:
cdnVersion
: A string representing the version of HugeRTE to be loaded from the jsDelivr CDN. This is only applied if thehugerte
global variable isn't already defined and theHUGERTE_SCRIPT_SRC
injection token (see below for more info about it) isn't provided. By default, version 1 (that is, the latest minor and patch release of the major version 1) will be used. For more info about the possible version formats, see the jsDelivr documentation. Note that loading by tag orlatest
will currently throw a type error.disabled
: A boolean indicating whether the editor should be disabled. Default isfalse
.id
: A unique string identifier for the editor instance. If not provided, a unique id will be generated.init
: An object of options to be passed to thehugerte.init()
method.initialValue
: A string representing the initial content to be loaded into the editor. If not provided, the editor will be empty.outputFormat
: Specifies the format of the editor's output when using forms or plain data bindings. Can be either html or text. Default is html.inline
: A boolean indicating if the editor should be rendered inline. Default isfalse
.tagName
: The HTML tag name to be used for the editor element if rendered in inline mode. Default isdiv
. This has no effect when not rendering the editor in inline mode.plugins
: An array or a string listing the plugins to be used by the editor. This will be added as theplugins
option of object passed to thehugerte.init()
method.toolbar
: An array or a string defining the items to be included in the editor's toolbar. This will be added as thetoolbar
option of object passed to thehugerte.init()
method.modelEvents
: An array or a space-separated string specifying the events that should trigger an emit of theNgModelChange
. Default ischange input undo redo
.allowedEvents
: An array or a comma-separated string specifying the events that should be allowed to trigger from the editor to thehugerte-angular
component. By default, all events defined in this array, mapped to beon
-prefixed, plusonInitNgModel
andonPreInit
will be allowed to trigger.ignoreEvents
: An array or a comma-separated string specifying the events that should not be allowed to trigger from the editor to thehugerte-angular
component, no matter ifallowedEvents
is set or not.
By default, if no hugerte
global variable is already present on globalThis
(window
), the editor will be loaded from the jsDelivr CDN. However, you can also self-host the editor. You can either bundle the HugeRTE scripts or let Angular copy the node_modules/hugerte
folder to an output hugerte
folder. We recommend the first approach.
Please follow the bundling guide. Make sure to include the hugerte
imports before the @hugerte/hugerte-angular
import.
When using the hugerte
npm package, add this to your angular.json
file:
"assets": [
{ "glob": "**/*", "input": "node_modules/hugerte", "output": "/hugerte/" }
]
This is not required when manually downloading HugeRTE distribution files from https://github.com/hugerte/hugerte-dist. (But we recommend using npm instead.)
Import both the EditorModule
or EditorComponent
and the HUGERTE_SCRIPT_SRC
injection token from @hugerte/hugerte-angular
.
import { EditorModule, HUGERTE_SCRIPT_SRC } from '@hugerte/hugerte-angular';
// or:
import { EditorComponent, HUGERTE_SCRIPT_SRC } from '@hugerte/hugerte-angular';
Then, add this object as an item to your providers
array in your module/component:
{ provide: HUGERTE_SCRIPT_SRC, useValue: 'hugerte/hugerte.min.js' }
Add this to your global scripts in your angular.json
file:
"scripts": [
"node_modules/tinymce/tinymce.min.js"
]
Then in the init
option passed to the editor component, add the base_url
and suffix
options:
<editor [init]="{base_url: '/hugerte', suffix: '.min'}"></editor>
Use the ngModel
directive:
<editor [(ngModel)]="yourDataModel"></editor>
Consult the Angular documentation on NgModel in forms for more information.
Include the <editor>
within a form group, then use the formControlName
directive:
<editor [formControlName]="schema.key"></editor>
Consult the Angular documentation on reactive forms for more information.
You can bind to any event in the events list (except those you exclude by the ignoreEvents
option and/or don't set in the allowedEvents
option, if you include it), but you'll have to prefix each one with on
. Plus, the onInitNgModel
and onPreInit
events, which aren't included in the list linked above, are also supported.
<editor (onSelectionChange)="handleEvent($event)"></editor>
The $event variable will have the event
(HugeRTE event object) and editor
properties.
- Replace
tinymce
byhugerte
(@tinymce/tinymce-angular
to@hugerte/hugerte-angular
). - Review the changelog.
The hugerte/hugerte-angular repo comes with a storybook showing examples of integrating HugeRTE with Angular. To run the storybook, follow the following steps:
- Clone the repo:
git clone https://github.com/hugerte/hugerte-angular
- Install dependencies:
yarn
- Run the storybook:
yarn storybook
This component requires Angular 17+.
Have you found an issue with hugerte-angular or do you have a feature request? Open up an issue and let us know or submit a pull request by forking this repo, making the appropiate changes,then going to the pull request tab in your fork and creating one. Note: for issues concerning HugeRTE itself please visit the HugeRTE repository.