mirror of https://github.com/abpframework/abp
parent
9c6a936819
commit
1ad41ca926
@ -0,0 +1,95 @@
|
||||
# ContentStrategy
|
||||
|
||||
`ContentStrategy` is an abstract class exposed by @abp/ng.core package. It helps you create inline scripts or styles.
|
||||
|
||||
## API
|
||||
|
||||
|
||||
### constructor
|
||||
|
||||
```js
|
||||
constructor(
|
||||
public content: string,
|
||||
protected domStrategy?: DomStrategy,
|
||||
protected contentSecurityStrategy?: ContentSecurityStrategy
|
||||
)
|
||||
```
|
||||
|
||||
- `content` is set to `<script>` and `<style>` elements as `textContent` property.
|
||||
- `domStrategy` is the `DomStrategy` that will be used when inserting the created element. (_default: AppendToHead_)
|
||||
- `contentSecurityStrategy` is the `ContentSecurityStrategy` that will be used on the created element before inserting it. (_default: None_)
|
||||
|
||||
Please refer to [DomStrategy](./Dom-Strategy.md) and [ContentSecurityStrategy](./Content-Security-Strategy.md) documentation for their usage.
|
||||
|
||||
|
||||
### createElement
|
||||
|
||||
```js
|
||||
createElement(): HTMLScriptElement | HTMLStyleElement
|
||||
```
|
||||
|
||||
This method creates and returns a `<script>` or `<style>` element with `content` set as `textContent`.
|
||||
|
||||
|
||||
### insertElement
|
||||
|
||||
```js
|
||||
insertElement(): void
|
||||
```
|
||||
|
||||
This method creates and inserts a `<script>` or `<style>` element.
|
||||
|
||||
|
||||
## ScriptContentStrategy
|
||||
|
||||
`ScriptContentStrategy` is a class that extends `ContentStrategy`. It lets you **insert a `<script>` element to the DOM**.
|
||||
|
||||
## StyleContentStrategy
|
||||
|
||||
`StyleContentStrategy` is a class that extends `ContentStrategy`. It lets you **insert a `<style>` element to the DOM**.
|
||||
|
||||
|
||||
## Predefined Content Strategies
|
||||
|
||||
Predefined content strategies are accessible via `CONTENT_STRATEGY` constant.
|
||||
|
||||
|
||||
### AppendScriptToBody
|
||||
|
||||
```js
|
||||
AppendScriptToBody(content: string)
|
||||
```
|
||||
|
||||
Creates a `<script>` element with the given content and places it at the **end** of `<body>` tag in the document.
|
||||
|
||||
|
||||
### AppendScriptToHead
|
||||
|
||||
```js
|
||||
AppendScriptToHead(content: string)
|
||||
```
|
||||
|
||||
Creates a `<script>` element with the given content and places it at the **end** of `<head>` tag in the document.
|
||||
|
||||
|
||||
### AppendStyleToHead
|
||||
|
||||
```js
|
||||
AppendStyleToHead(content: string)
|
||||
```
|
||||
|
||||
Creates a `<style>` element with the given content and places it at the **end** of `<head>` tag in the document.
|
||||
|
||||
|
||||
### PrependStyleToHead
|
||||
|
||||
```js
|
||||
PrependStyleToHead(content: string)
|
||||
```
|
||||
|
||||
Creates a `<style>` element with the given content and places it at the **beginning** of `<head>` tag in the document.
|
||||
|
||||
|
||||
## See Also
|
||||
|
||||
TODO: Place DomInsertionService documentation link here.
|
Loading…
Reference in new issue