版本
语言

ContentStrategy

ContentStrategy 是@abp/ng.core包暴露出的抽象类. 它可以帮助你创建内联脚本或样式.

API

构造函数

constructor(
  public content: string,
  protected domStrategy?: DomStrategy,
  protected contentSecurityStrategy?: ContentSecurityStrategy
)
  • content 是被设置为 <script><style> 元素的 textContent 属性.
  • domStrategy 是在插入创建的元素时将使用的 DomStrategy . (默认值: AppendToHead_)
  • contentSecurityStrategyContentSecurityStrategy, 在创建的元素插入使用它它. (默认值: None_)

请参考DomStrategyContentSecurityStrategy文档了解它们的用法.

createElement

createElement(): HTMLScriptElement | HTMLStyleElement

该方法创建并且返回 <script><style> 元素, 将 content 设置为 textContent.

insertElement

insertElement(): void

该方法创建并且插入一个 <script><style> 元素.

ScriptContentStrategy

ScriptContentStrategy 是扩展了 ContentStrategy 的类. 你可以使用它将 <script>元素插入DOM.

StyleContentStrategy

StyleContentStrategy 是扩展了 ContentStrategy 的类. 你可以使用它将 <style>元素插入DOM.

预定义内容策略

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

AppendScriptToBody

CONTENT_STRATEGY.AppendScriptToBody(content: string)

创建具有给定内容的 <script> 元素, 并放置在文档中<body>标记的末尾.

AppendScriptToHead

CONTENT_STRATEGY.AppendScriptToHead(content: string)

创建具有给定内容的 <script> 元素, 并放置在文档中<head>标签的末尾.

AppendStyleToHead

CONTENT_STRATEGY.AppendStyleToHead(content: string)

创建具有给定内容的 <style> 元素, 并放置在文档中<head>标签的末尾.

PrependStyleToHead

CONTENT_STRATEGY.PrependStyleToHead(content: string)

创建具有给定内容的 <style> 元素, 并放置在文档中<head>标签的头部.

另请参阅

本页对您有帮助吗?
请进行选择。
感谢您的宝贵意见!

请注意,虽然我们无法回复反馈意见,但我们的团队会根据您的意见改进体验。

在本文档中
Mastering ABP Framework Book
掌握 ABP 框架

本书将帮助你全面了解框架和现代Web应用程序开发技术。