多亏了这个小提琴和一些玩耍,我在一段时间后设法做到了这一点。See here。
component.html:
<quill-editor [(ngModel)]="editorContent"
[options]="editorOptions"
(ready)="onEditorCreated($event)"
(change)="onContentChanged($event)"></quill-editor>
component.ts:
public editor;
public editorContent = '<h3>Type Something...</h3>';
public editorOptions = {
theme: 'snow',
modules: {
toolbar: {
container:
[
[{ 'placeholder': ['[GuestName]', '[HotelName]'] }], // my custom dropdown
['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
],
handlers: {
"placeholder": function (value) {
if (value) {
const cursorPosition = this.quill.getSelection().index;
this.quill.insertText(cursorPosition, value);
this.quill.setSelection(cursorPosition + value.length);
}
}
}
}
}
};
constructor(private elem: ElementRef) {
}
onEditorCreated(quill) {
this.editor = quill;
console.log('quill is ready! this is current quill instance object', quill);
}
onContentChanged({ quill, html, text }) {
console.log('quill content is changed!', quill, html, text);
}
ngAfterViewInit() {
// Update your dropdown with labels
let placeholderPickerItems = this.elem.nativeElement.querySelectorAll('.ql-placeholder .ql-picker-item');
placeholderPickerItems.forEach(item => item.textContent = item.dataset.value);
this.elem.nativeElement.querySelector('.ql-placeholder .ql-picker-label').innerHTML
= 'Insert Data Field ' + this.elem.nativeElement.querySelector('.ql-placeholder .ql-picker-label').innerHTML;
}
输出:
Screenshot of Output
希望这会有所帮助!