ng-quill is an Angular.js component for Quill rich text editor.
If you like my work, feel free to support it. Donations to the project are always welcomed :)
PayPal: PayPal.Me/bengtler
BTC Wallet Address:
3QVyr2tpRLBCw1kBQ59sTDraV6DTswq8Li
ETH Wallet Address:
0x394d44f3b6e3a4f7b4d44991e7654b0cab4af68f
LTC Wallet Address:
MFif769WSZ1g7ReAzzDE7TJVqtkFpmoTyT
npm install ng-quill
npm install angular angular-sanitize quill
The new version is complete rewritten and is using QuillJS 1.x. For the latest old version (0.20.1) checkout the special branch for it.
var myAppModule = angular.module('quillTest', ['ngQuill']);
<ng-quill-editor ng-model="message"></ng-quill-editor>
[ng-quill-editor] { display: block; }
ng-quill-toolbar
- it uses transclusion to add toolbar, avoids flickering and sets the modules toolbar config to the custom toolbar automatically:<ng-quill-editor ng-model="title">
<ng-quill-toolbar>
<div>
<span class="ql-formats">
<button class="ql-bold" ng-attr-title="Bold"></button>
</span>
<span class="ql-formats">
<select class="ql-align" ng-attr-title="Aligment">
<option selected></option>
<option value="center"></option>
<option value="right"></option>
<option value="justify"></option>
</select>
<select class="ql-align">
<option selected></option>
<option value="center"></option>
<option value="right"></option>
<option value="justify"></option>
</select>
</span>
</div>
</ng-quill-toolbar>
</ng-quill-editor>
top
, possible values top
, bottom
let app = angular.module('app', [ 'ngQuill' ])
app.constant('NG_QUILL_CONFIG', {
/*
* @NOTE: this config/output is not localizable.
*/
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['clean'], // remove formatting button
['link', 'image', 'video'] // link and image, video
]
},
theme: 'snow',
debug: 'warn',
placeholder: '',
readOnly: false,
bounds: document.body,
scrollContainer: null
})
app.config([
'ngQuillConfigProvider',
'NG_QUILL_CONFIG',
function (ngQuillConfigProvider, NG_QUILL_CONFIG) {
ngQuillConfigProvider.set(NG_QUILL_CONFIG)
}
])
*see: ./src/ng-quill/app.provider(‘ngQuillConfig’).config
ngQuillConfigProvider.set({modules: { ... }, theme: 'snow', placeholder: 'placeholder', formats: { ... }, bounds: document.body, readyOnly: false) to config toolbar module, other modules, default theme, allowed formats, ...
theme="snow"
(default: ‘snow’)read-only=""
(default: false) - requires true or falsemodules="modulesConfig"
placeholder="'Inser your text here'"
or placeholder="''"
for empty stringbounds="..."
, change the default boundary element of the editor (document.body
) - set it to ‘self’ and the editor element is usedformats="formatsArray"
, per default all quill formats are allowedmax-length="5"
, adds validation for maxlength (sets model state to invalid
and adds ng-invalid-maxlength
class)min-length="5"
, adds validation for minlength (sets model state to invalid
and adds ng-invalid-minlength
class), only works for values > 1, if you only want to check if there is a value –> use required/ng-requiredtrue
)format - default ‘html’, possible values ‘json’ | ‘object’ | ‘html’ | ‘text’, so you are able to set quill operation object, html or plain text to your model |
styles="{ backgroundColor: 'red' }"
html
(default: false
)'error', 'warn', 'log', true, false
(default: 'warn'
)user
(quill source user) or all
change should be trigger model update, default user
. Using all
is not recommended, it cause some unexpected sideeffects. But useful for 3rd Party modules and blots to keep your model up to datepreserveWhitespace - default: false - possbility to use a pre-tag instead of a div-tag for the contenteditable area to preserve duplicated whitespaces | caution if used with syntax plugin Related issue |
on-editor-created="myCallback(editor)"
on-content-changed="myCallback(editor, html, text, content, delta, oldDelta, source)"
on-selection-changed="myCallback(editor, range, oldRange, source)"
- content = quill editor content object, text = content as plain text, html = content as html stringon-focus="myCallback(editor, source)"
on-blur="myCallback(editor, source)"
Angular templates provide some assurance against XSS in the form of client side sanitizing of all inputs.
Ng-quill provides the config paramter sanitize to sanitize html-strings passed as ngModel to the component.
It is deactivated per default to avoid stripping content or styling, which is not expected.
But it is recommended to activate this option, if you are working with html strings as model values.
After editor creation you can use everything from the ordinary quill editor -> listen to editorCreated and work with the editor instance in your controller like you want ;). Add modules, use the quill API or listen to Events. Keep in mind to use $timeout if you are listening / working with quill-Events and updating some $scope stuff to notify angular about it ;). Quill Documentation