| layout | landing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| highlights |
|
Angular Dynamic Hooks can load Angular components into any dynamic content, such as strings, individual HTML elements or the whole browser page.
What if you wanted to load components not just from static templates, but from dynamic content - such as string variables, HTML elements or even a live webpage?
By default, this is not easily possible.
Angular Dynamic Hooks aims to solve this problem. It offers a simple way to load Angular components into so-called hooks. Hooks can be HTML elements or text patterns.
{% capture guideFirstStep %}
```bash
npm install ngx-dynamic-hooks
```
{% endcapture %}
{% capture guideSecondStep %}
```ts
import { DynamicHooksComponent } from 'ngx-dynamic-hooks';
{% endcapture %}
@Component({ ... imports: [DynamicHooksComponent] })
</div>
{% endcapture %}
{% capture guideThirdStep %}
<div class="l-guide-step-code" markdown="1">
```ts
// The content to parse
content = 'Load a component here: <app-example></app-example>';
// A list of components to look for
parsers = [ExampleComponent];
{% capture guideFourthStep %}
```html
```
{% endcapture %}
<div class="l-guide-step">
<div class="l-guide-step-nr">1</div>
<div class="l-guide-step-content">
<div class="l-guide-step-text">
<p>Install the library with</p>
</div>
{{ guideFirstStep }}
</div>
</div>
<div class="l-guide-arrow"><img src="{{ "/assets/images/narrow_arrow_down.png" | relative_url }}" alt="An arrow pointing downwards"></div>
<div class="l-guide-step">
<div class="l-guide-step-nr">2</div>
<div class="l-guide-step-content">
<div class="l-guide-step-text">
<p>Import the <b>DynamicHooksComponent</b> wherever you need it</p>
</div>
{{ guideSecondStep }}
</div>
</div>
<div class="l-guide-arrow"><img src="{{ "/assets/images/narrow_arrow_down.png" | relative_url }}" alt="An arrow pointing downwards"></div>
<div class="l-guide-step">
<div class="l-guide-step-nr">3</div>
<div class="l-guide-step-content">
<div class="l-guide-step-text">
<p>Get your content and components to load</p>
</div>
{{ guideThirdStep }}
</div>
</div>
<div class="l-guide-arrow"><img src="{{ "/assets/images/narrow_arrow_down.png" | relative_url }}" alt="An arrow pointing downwards"></div>
<div class="l-guide-step">
<div class="l-guide-step-nr">4</div>
<div class="l-guide-step-content">
<div class="l-guide-step-text">
<p>And pass them to <i><ngx-dynamic-hooks></i></p>
</div>
{{ guideFourthStep }}
</div>
</div>
</div>
<div class="l-guide-result">
<p class="l-guide-result-line"><b>That's it!</b> The content will now be rendered with a working <b>ExampleComponent</b> in it! 🎉</p>
<a class="l-guide-result-button" href="{{ "guide" | relative_url }}">📄 To the full documentation </a>
</div>
</div>