【发布时间】:2017-06-01 22:31:22
【问题描述】:
我正在尝试创建一个所见即所得的编辑器,我已经完成了:
export class WysiwygEditorComponent extends OnInit {
editor:any;
ngOnInit() {
this.editor = document.getElementById('editor')
}
iBold() {
this.editor.execCommand('bold', false, null);
}
}
这是它的 HTML:
<div>
<input type="button" (click)="iBold()" value="B">
</div>
<div id='editor' contenteditable>
<h1>A WYSIWYG Editor.</h1>
<p>Try making some changes here. Add your own text.</p>
</div>
这是我的错误:
TypeError: Cannot read property 'document' of undefined
at WysiwygEditorComponent.iBold
如何获取 html 元素以便我可以调用 execCommand,以便它可以根据调用的函数进行更改?
【问题讨论】:
-
我对@987654325@不太熟悉,但根据我有限的研究,它似乎是
document上的一种方法,而不是HTML元素 -
WysiwygEditorComponent的选择器是什么? -
@snorkpete - 非常感谢。我犯了较早的错误并且没有返回使用文档,但只是一个更改修复了它。如果您将您的评论作为答案,我会接受。
-
如果您有答案,请将其作为答案发布,而不是作为问题的一部分。
标签: javascript angular typescript wysiwyg