项目

内容策略

ContentStrategy 是由 @abp/ng.core 包提供的抽象类,可帮助您创建内联脚本或样式。

API

构造函数

constructor(
  public content: string,
  protected domStrategy?: DomStrategy,
  protected contentSecurityStrategy?: ContentSecurityStrategy,
  protected options?: ElementOptions = {},
)
  • content 将作为 textContent 属性设置到 <script><style> 元素中
  • domStrategy 是插入创建的元素时将使用的 DomStrategy默认:AppendToHead
  • contentSecurityStrategy 是在插入创建的元素之前将使用的 ContentSecurityStrategy默认:None
  • options 可用于向将要创建的元素传递任何选项,例如:{ id: "some-id" }默认:空对象

请参阅 DomStrategyContentSecurityStrategy 文档了解其用法。

createElement

createElement(): HTMLScriptElement | HTMLStyleElement

此方法创建并返回一个 <script><style> 元素,其中 content 作为 textContent 设置。

insertElement

insertElement(): void

此方法创建并插入一个 <script><style> 元素。

ScriptContentStrategy

ScriptContentStrategy 是继承自 ContentStrategy 的类,它允许您向 DOM 中插入 <script> 元素

StyleContentStrategy

StyleContentStrategy 是继承自 ContentStrategy 的类,它允许您向 DOM 中插入 <style> 元素

预定义内容策略

预定义的内容策略可通过 CONTENT_STRATEGY 常量访问。

AppendScriptToBody

CONTENT_STRATEGY.AppendScriptToBody(content: string, options?: ElementOptions<HTMLScriptElement>)

创建一个带有给定内容的 <script> 元素,并将其放置在文档 <body> 标签的末尾

AppendScriptToHead

CONTENT_STRATEGY.AppendScriptToHead(content: string, options?: ElementOptions<HTMLScriptElement>)

创建一个带有给定内容的 <script> 元素,并将其放置在文档 <head> 标签的末尾

AppendStyleToHead

CONTENT_STRATEGY.AppendStyleToHead(content: string, options?: ElementOptions<HTMLStyleElement>)

创建一个带有给定内容的 <style> 元素,并将其放置在文档 <head> 标签的末尾

PrependStyleToHead

CONTENT_STRATEGY.PrependStyleToHead(content: string, options?: ElementOptions<HTMLStyleElement>)

创建一个带有给定内容的 <style> 元素,并将其放置在文档 <head> 标签的开头

另请参阅

在本文档中