Angular: <ol> 添加的 document.execCommand 只看到 style.css 中的 css 规则而不是组件的 css

问题描述

我正在 angular 中创建富文本编辑器,当我执行 document.execCommand('insertOrderedList') 时,我得到 <ol> 项,它不受我组件的 css 的影响,只有 styles.css 中的 css(主 css 文件在项目的根目录)影响我使用 document.execCommand 添加的项目。 是否有可能改变这种行为?

解决方法

当然。它的名字是view encapsulation。将其更改为 ViewEncapsulation.none 会产生所需的行为。

@Component({
  ...
  encapsulation: ViewEncapsulation.none
})

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...