tinymce angular 2+ 模板没有用 ngmodel 替换 init 上的值,但是带有用户插入的模板

tinymce angular 2+ templates not replacing values on init with ngmodel, but are with templates inserted by user

我在 Angular 7 应用程序中使用 TinyMCE 编辑器组件。当我将模板变量插入编辑器时:

<span class="data-variable">${variable_name}</span>

它被替换为我的 template_replace_values 对象的值,我用它初始化 tinymce。

let template_replace_values = {variable_name: "hello world!"}

输出:

<span class="data-variable">hello world!</span>

但是,当模板 html 通过 ngModel 绑定填充时:

<editor #editor [(ngModel)]="html" (onChange)="updateStore(html)"></editor>

html 的插入方式如下:

<span class="data-variable">${variable_name}</span>

并且没有替换发生。我是否需要以某种方式从 angular 生命周期连接到 tinymce 事件?

您引用的功能是 template 插件的一部分,因此它仅在您使用该插件插入内容时触发。使用其他 API 将内容注入编辑器不会触发该代码,因此不会发生替换。

我们确实有编辑器事件可以在内容插入编辑器时通知您,您当然可以选择在这些事件发生时自己执行替换。