Example:
Parent component:
<div>
Hello <slot/>!
</div>
Child Component:
<div>
World
</div>
App component:
<Parent>
<Child/>
</Parent>
Output: Hello World!
Single-slot content projection refers to creating a component into which you can project one component. To create a component that uses single-slot content projection: Create a component. In the template for your component, add an <ng-content> element where you want the projected content to appear.
Slot props allow us to turn slots into reusable templates that can render different content based on input props. This is most useful when you are designing a reusable component that encapsulates data logic while allowing the consuming parent component to customize part of its layout.
If you know how to use HTML, CSS, and have basic JavaScript knowledge, you are good to go to start learning Vue. Angular uses Typescript which is a superset of JavaScript and the learning curve is pretty steep. You should know you have to invest a lot of time into learning Angular.
js — Using a stateful Angular-like service to organize your code.
We have something like this in Angular.
The directive <ng-content>
is used to project outer content into the current component, and you can use a selector to project specific content with a CSS style query.
app-example.html:
<div>
<ng-content></ng-content>
</div>
<div>
<ng-content selector=".child"></ng-content>
</div>
app-component.html
<app-example>
<span class="child">World</span>
Hello
</app-example>
Renders this output:
<app-example>
<div>Hello</div>
<div><span class="child">World</span></div>
</app-example>
In angular its called "Content Projection", and there are three types
1) Single-slot content projection With this type of content projection, a component accepts content from a single source.
Is content projection cool?
2) Multi-slot content projection Is content projection cool?
Let's learn about content projection!
In this scenario, a component accepts content from multiple sources.3) Conditional content projection Components that use conditional content projection render content only when specific conditions are met.
Source: https://angular.io/guide/content-projection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With