回答
假設你正在實施@Directive
的解釋在TinyMCE official documentation:
加一個額外的@Input
參數:
@Input() initialContent: String;
在ngAfterViewInit()
你必須把 tinymce.init({})
對象與編輯器的配置和運行時選項。它的存在,你還可以添加新的功能:
init_instance_callback: (editor: any) => {
editor && this.initialContent && this.editor.setContent(this.initialContent)
},
最後,當你呼叫的指令,你必須爲你的@Input
參數使用比你在使用相同的名稱添加一個新的屬性指令的定義。
<textarea class="form-control" id="wysiwygText" name="body" rows="3" [htmlEditor] initialContent="{{model.body}}" [(ngModel)]="model.body" #body="ngModel" (onEditorKeyup)="keyupHandlerFunction($event)"></textarea>
這個實現是基於this article
你必須實施的一個包裝,或嘗試將現有的 https://github.com/zackarychapple/ng2-tinymce-wyswig
https://github.com/luigiinred/ng2-tinymce
或者我知道這個工程肯定的:https://github.com/chymz/ng2-ckeditor
評論我有同樣的問題,並實現@nicofx答案。但是,當內容由異步http調用設置時,這並沒有訣竅。
具有相同問題的人:你可以使用哪些更新時,HTTP調用已完成conent的eventemitter:
定義輸入:
@Input() contentEvent: EventEmitter<string>;
訂閱eventemitter如果傳遞:
ngAfterViewInit() {
tinymce.init({
selector: '#' + this.elementId,
plugins: ['link', 'paste', 'table'],
skin_url: '/assets/skins/lightgray',
setup: editor => {
this.editor = editor;
if (this.contentEvent) {
this.contentEvent.subscribe(c => {
this.setContent(editor, c);
});
}
}
});
}
而且setcontent功能:
private setContent(editor, content) {
if (editor && content) {
this.editor.setContent(content);
}
}
你也可以做得更簡單一點。 只需添加文字@input在你看來,你用tinyMCE的組件:
<tinymce-editor
[desiredInitialText]="text"
(onEditorKeyup)="editorChangesHandler($event)">
</tinymce-editor>
然後在你的TinymceComponent添加
@Input() desiredInitialText: string //Or any other special typing
...
ngOnChanges() {
if (this.editor) {
if (this.desiredInitialText && this.desiredInitialText.length > 0) {
this.editor.setContent(this.desiredInitialText)
} else {
this.editor.setContent('');
}
}
}
這可能是有益的
import { Component, AfterViewInit, OnDestroy, Input, Output, EventEmitter, ElementRef, provide, forwardRef, View } from 'angular2/core';
import { RdComponent, RdLib } from '../../../../../node_modules/mulberry/core';
declare let tinymce: any;
@Component({
selector: 'aril-mail-template',
template: `<textarea style="height:15em"><p>{{model}}</p></textarea>`
})
export class MailTemplatesComponent extends RdComponent {
@Input("rd-model") model;
@Input("rd-default") default;
@Input("rd-required") required;
@Output("mail-template-save") mailTemplateSave: EventEmitter<any> = new EventEmitter<any>();
editor;
ngOnInit() {
let that = this;
tinymce.init({
selector: 'textarea',
height: "25em",
menubar: true,
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen hr',
'insertdatetime media table contextmenu paste spellchecker',
'wordcount'
],
toolbar: 'styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image spellchecker code',
table_toolbar: "tableprops cellprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol",
powerpaste_allow_local_images: true,
powerpaste_word_import: 'prompt',
powerpaste_html_import: 'prompt',
spellchecker_language: 'en',
spellchecker_dialog: true,
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css'],
setup: editor => {
this.editor = editor;
editor.on('init',() => {
this.model && this.editor.setContent(this.model, {format: 'raw'});
});
editor.on('change',() => {
const content = editor.getContent();
this.mailTemplateSave.emit(content);
});
}
});
}
ngOnDestroy() {
tinymce.remove(this.editor);
}
}
<rd-service-provider #saveMailTemplateProvider [rd-service-proxy]="serviceProxy" (rd-success)="toastr.info(translate('Mail Şablonu Başarıyla Oluşturuldu.'));close()"></rd-service-provider>
<aril-mail-template [(rd-model)]="data.MailContent" (mail-template-save)="mailContent = $event" [rd-required]="true"></aril-mail-template>
<rd-footer>
<rd-submit [rd-text]="translate('Save')" rd-size="medium" (rd- click)="saveMailTemplateProvider.call(saveMailTemplates($event, mailContent))"></rd-submit>
</rd-footer>
您的代碼段產生錯誤 –
- 1. TinyMCE&Angular 2:基於@Input設置編輯器內容
- 2. 如何在編輯器初始化後在ng2-lazy-trumbowyg編輯器中設置內容? Angular 2/4
- 3. 初始化爲tinyMCE textarea並在選定的tinyMCE編輯器上設置內容
- 4. 如何在ASP.NET MVC4(Razor)中設置TinyMCE編輯器的初始內容?
- 5. 如何在Tinymce Wordpress編輯器中設置父級選擇標籤的內容
- 6. TinyMCE圖像編輯器集成
- 7. 如何設置TinyMCE的內容動態
- 8. 如何設置tinymce默認內容
- 9. 內聯編輯器tinymce
- 10. Angular JS - 編輯內容編輯
- 11. 如何防止用戶修改tinymce編輯器內容。用戶不應該編輯內容。如何使用angularjs
- 12. 如何將照片上傳與Rails3.1應用中的tinymce內容編輯器集成?
- 13. 如何以編程方式設置/編輯webview的內容
- 14. tinyMCE編輯器在tinyMCE容器上的邊距
- 15. TinyMce in Angular 2
- 16. 如何班TinyMCE的表格編輯器
- 17. 設置數據在TinyMCE編輯
- 18. 重置tinyMce內容
- 19. Android:如何設置按鈕點擊編輯文本的內容?
- 20. Drupal:如何設置編輯內容字段的摺疊屬性
- 21. 如何設置html內容固定寬度的可編輯div
- 22. 當我們編輯/創建主體內容時,TinyMCE編輯器沒有顯示
- 23. TinyMCE插件InsertContent刪除編輯器內容
- 24. 從TinyMCE編輯器獲取特定內容
- 25. TinyMCE插件中的TinyMCE編輯器
- 26. 如何預加載tinymce編輯器?
- 27. Angular-2 Mapzen集成
- 28. Angular 2如何編輯元素名稱?
- 29. 如何在tinymce中設置特定節點的內容?
- 30. 如何使用Nightwatch.js設置tinyMCE的內容
我想自己做,而不改變整個邏輯通過添加一個包裝。 –
我建議實現一個自定義的tinyMCE組件,它接受一個'@ Input',呈現一個tinyMCE編輯器,並通過'@ Input'傳遞給Edior的值通過http://archive.tinymce.com/wiki.php/設置。 API3:method.tinymce.Editor.setContent – bergben