内容策略
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" }(默认:空对象)
请参阅 DomStrategy 和 ContentSecurityStrategy 文档了解其用法。
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> 标签的开头。
抠丁客


