Ok, with some more hints from the web I found a solution:
This is in the TypeScript file, a configuration for the editor:
tinyMceConfig: any;
filter: Filter[] = [];
ngOnInit() {
// this.loadData();
this.configureTinyMce();
}
configureTinyMce() {
const that = this;
this.tinyMceConfig = {
menubar: false,
branding: false,
height: 300,
base_url: '/tinymce',
suffix: '.min',
inline: false,
toolbar: 'filterbutton',
setup: function (editor) {
const test = that.filter.map(f => { return {
type: 'nestedmenuitem',
text: f.templateVariableName,
icon: 'template',
getSubmenuItems: function() {
return f.fieldNames.map( field => { return {
type: 'menuitem',
text: field.memberName,
icon: 'paste-text',
onAction: function () {
editor.insertContent('{{' + f.templateVariableName + '.' + field.memberName + '}}');
}
}; });
}
}; });
/* example, adding a toolbar menu button */
editor.ui.registry.addMenuButton('filterbutton', {
text: 'Filter',
fetch: function (callback) {
callback(test);
}
});
}
};
}
With the
const test
I am using and transforming an object from outside of the function into the corresponding syntax for a TinyMCE menu item.
In the HTML template file it looks like this:
<editor
formControlName="desktophtml"
required
name="desktophtml"
[init]="tinyMceConfig">
</editor>
The object (named 'filter') I am using to feed the editor looks something like this:
{
templateVariableName: 'foo',
fieldNames: [ {
memberName: 'bar'
}]
}
This is the model file:
export class Filter {
templateVariableName: string;
fieldNames: [any];
}
I hope this will save someone a lot of time ;)