在Angular 8中使用WYSIWYG编辑器和innerHTML的解决方法如下:
npm install ngx-quill
import { QuillModule } from 'ngx-quill';
@NgModule({
imports: [
QuillModule.forRoot()
],
...
})
export class AppModule { }
content: string = 'Hello, world!
';
getContent() {
return this.content;
}
然后,在组件的模板文件中使用innerHTML绑定来显示编辑器的内容:
这样,编辑器的内容将显示在div元素中。
请注意,使用innerHTML绑定时要小心,以避免潜在的安全风险。确保只将受信任的内容绑定到innerHTML属性中,并始终遵循最佳安全实践。