Angular TinyMCE&;角度2:设置编辑器';s基于@Input的内容
tinymce新手,不确定setContent(this.content)方法的实际位置。我的当前版本导致我出错:Angular TinyMCE&;角度2:设置编辑器';s基于@Input的内容,angular,data-binding,tinymce,Angular,Data Binding,Tinymce,tinymce新手,不确定setContent(this.content)方法的实际位置。我的当前版本导致我出错: TypeError:null不是对象(计算'body.nodeName')---runTask-zone.js:170 persona对象是通过查询我的数据库的服务检索的,该数据库工作正常 我在persona.component.html中设置了如下实例: <app-tinymce [elementId]="'persona-footnotes'" (onEdit
TypeError:null不是对象(计算'body.nodeName')---runTask-zone.js:170
persona对象是通过查询我的数据库的服务检索的,该数据库工作正常
我在persona.component.html中设置了如下实例:
<app-tinymce
[elementId]="'persona-footnotes'"
(onEditorContentChange)="keyupHandler($event)"
[content]="persona.footnotes"
></app-tinymce>
认为这是一个放置setContent(this.content)方法的位置/时间问题,但又一次,不确定放在哪里?您已经接近了。设置函数需要延迟
setContent()
调用,直到编辑器初始化。有这样一个活动,您可以尝试以下内容:
setup: editor => {
this.editor = editor;
editor.on('init', () => {
editor.setContent(this.content);
});
}
这将延迟对
setContent()
的调用,直到编辑器初始化并准备好使用API调用为止。以下是TinyMCE编辑器组件的完整代码。这可能会有帮助
import{Component,AfterViewInit,OnDestroy,Input,Output,EventEmitter,ElementRef,provide,forwardRef,View}来自'angular2/core';
从“../../../../../../node_modules/maryberry/core”导入{RdComponent,RdLib};
声明:任何;
@组成部分({
选择器:“aril邮件模板”,
模板:`{{model}}`
})
导出类MailTemplatesComponent扩展RdComponent{
@输入(“rd模型”)模型;
@输入(“rd默认值”)默认值;
@需要输入(“需要研发”);
@输出(“邮件模板保存”)mailTemplateSave:EventEmitter=neweventemitter();
编辑
恩戈尼尼特(){
让那=这;
tinymce.init({
选择器:'textarea',
高度:“25em”,
梅努巴:没错,
插件:[
'advlist autolink列出链接图像charmap打印预览锚',
“searchreplace visualblocks代码全屏hr”,
“insertdatetime媒体表上下文菜单粘贴拼写检查器”,
“字数”
],
工具栏:“样式选择|粗体斜体|对齐左对齐中心对齐右对齐对齐对齐对齐|粗体numlist outdent缩进|链接图像拼写检查代码”,
table_工具栏:“tableprops cellprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol”,
powerpaste\u允许\u本地\u图像:真,
powerpaste\u word\u导入:“提示”,
powerpaste_html_导入:“提示符”,
拼写检查器_语言:“en”,
拼写检查对话框:true,
内容(css):[
“//fonts.googleapis.com/css?family=Lato:300300i,400400i”,
“//www.tinymce.com/css/codepen.min.css'],
设置:编辑器=>{
this.editor=editor;
editor.on('init',()=>{
this.model&&this.editor.setContent(this.model,{format:'raw'});
});
编辑器.on('change',()=>{
const content=editor.getContent();
this.mailTemplateSave.emit(内容);
});
}
});
}
恩贡德斯特罗(){
tinymce.remove(this.editor);
}
}
谢谢!这消除了错误,但在显示的数据上仍然有一些间歇性的成功。我还添加了*ngIf=“content.property”,使其在100%的时间内都能显示出来(我的开发系统在响应时间上有点不尽如人意)
setup: editor => {
this.editor = editor;
editor.on('init', () => {
editor.setContent(this.content);
});
}