我一直在成功將tinymce整合到angular2 cli中,現在我的問題是如何將組件的值綁定或傳遞到tinymce textarea。如何將組件中的數據綁定到使用角度2 cli的tinymce
例如,我有product.component.ts和product.component.html。 TinyMCE的指令是在product.component.html
product.component.html:
<simple-tiny
[elementId]="'my-editor-id'"
(onEditorKeyup)="keyupHandlerFunction($event)"
>
</simple-tiny>
product.component.ts
import { Component,Input,OnInit } from '@angular/core';
@Component({
selector: 'app-product',
templateUrl: './product.component.html'
})
export class ProductComponent {
my-editor-id:any -->error
ngOnInit(): void {
this.my-editor-id="abcdefg"; --> error, i want bind abcdefg into tinymce are? how?
}
}
簡單tiny.component.ts:
import {
Component,
OnDestroy,
AfterViewInit,
EventEmitter,
Input,
Output
} from '@angular/core';
@Component({
selector: 'simple-tiny',
template: `<textarea id="{{elementId}}"></textarea>`
})
export class SimpleTinyComponent implements AfterViewInit, OnDestroy {
@Input() elementId: String;
@Output() onEditorKeyup = new EventEmitter<any>();
editor;
ngAfterViewInit() {
tinymce.init({
selector: '#' + this.elementId,
plugins: ['link', 'paste', 'table'],
skin_url: 'assets/skins/lightgray',
setup: editor => {
this.editor = editor;
editor.on('keyup',() => {
const content = editor.getContent();
this.onEditorKeyup.emit(content);
});
},
});
}
ngOnDestroy() {
tinymce.remove(this.editor);
}
}
感謝您的答案,但我仍然confuse..what被編碼模板: ''??你能給我完整的例子嗎? –