最终设法找到了使用ng2文件上传的方法。下面的代码是编辑器组件的一部分,我在其中定义了tinyMCE的内容。我只讲最重要的部分。
HTML:
<textarea id="{{elementId}}"></textarea>
<input id='input' type="file" #fileInput ng2FileSelect [uploader]="uploadFile.uploader" style="display: none;"
accept="image/png,image/gif,image/jpeg"/>
类型脚本:
ngOnInit() {
this.uploadFile.uploader.onCompleteItem = (item: any, response: string, status: any, headers: any) => {
....
tinymce.activeEditor.insertContent('<img src="' + location + '"/>');
....
};
}
ngAfterViewInit() {
tinymce.init({
.....
setup: editor => {
this.editor = editor;
editor.on('keyup', () => {
const content = editor.getContent();
this.onEditorKeyup.emit(content);
});
editor.on('reset', function(e) {
editor.setContent('');
});
editor.addButton('mybutton', {
text: 'Image',
icon: 'image',
onclick: function() {
var input = document.getElementById('input');
input.click();
}
});
},
.....
}