新增了tinymce並且不確定實際放置setContent(this.content)方法的位置。我現在的版本是使我得到一個錯誤:TinyMCE&Angular 2:基於@Input設置編輯器內容
TypeError: null is not an object (evaluating 'body.nodeName') --- runTask — zone.js:170
的人物對象通過該查詢我的數據庫的服務,這是工作的正確檢索。
我有我的情況下,設立這樣一個在我persona.component.html:
<app-tinymce
[elementId]="'persona-footnotes'"
(onEditorContentChange)="keyupHandler($event)"
[content]="persona.footnotes"
></app-tinymce>
在App-tinymce.component.ts:
import {
Component,
AfterViewInit,
EventEmitter,
OnDestroy,
Input,
Output
} from '@angular/core';
import 'tinymce';
import 'tinymce/themes/modern';
import 'tinymce/plugins/table';
import 'tinymce/plugins/link';
import 'tinymce/plugins/paste';
import 'tinymce/plugins/lists';
import 'tinymce/plugins/advlist';
import 'tinymce/plugins/code';
declare let tinymce: any;
@Component({
selector: 'app-tinymce',
templateUrl: './tinymce.component.html',
styleUrls: ['./tinymce.component.scss']
})
export class TinymceComponent implements AfterViewInit, OnDestroy {
@Input() elementId: String;
@Input() content: String;
@Output() onEditorContentChange = new EventEmitter();
editor;
ngAfterViewInit() {
tinymce.init({
selector: '#' + this.elementId,
plugins: ['link', 'table', 'lists', 'advlist', 'code'],
skin_url: '/assets/tinymce/skins/lightgray',
toolbar: [
'bold italic underline strikethrough subscript superscript removeformat | formatselect | fontsizeselect | bullist numlist outdent indent | link table | code'
],
menubar:'edit',
theme:'modern',
height:'300',
setup: editor => {
editor.setContent(this.content);
console.log(this.content); // this part outputs the correct data
this.editor = editor;
editor.on('keyup change',() => {
const content = editor.getContent();
this.onEditorContentChange.emit(content);
});
}
});
}
ngOnDestroy() {
tinymce.remove(this.editor);
}
}
認爲這是一個事where /「何時」放置setContent(this.content)方法,但又不知道在哪裏?
謝謝!這消除了錯誤,但仍然在數據顯示上間歇性地取得了成功。我還添加了* ngIf =「content.property」,並且它顯示了100%的時間(我的開發系統在這裏和那裏的響應時間都有點不足)。 – Eric