> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Content projection

`<ng-content>` lets a component wrap content that its parent passes in. Cards, labels and every [UI component](/dolan/index.md) are built this way. It works on [Lynx](/guide/glossary.md#lynx), with three rules that come from Lynx's elements.

## The Lynx rules

1. **Projected text belongs inside a `<text>`.** Lynx draws text only in a `<text>`. If your component takes text, put the `<ng-content>` inside a `<text>`, so your styles reach it. Text projected into a `<view>` still shows, in a `<text>` of its own that takes the text styles of its ancestors' classes.
2. **A nested `<text>` is inline.** When the parent passes `<text>` elements into your `<text>`, they flow as styled runs, like `<span>`s.
3. **The host element is a real box.** `<app-card>` becomes a plain, unstyled `<view>` in the layout, between the parent and your template. Every static attribute the parent writes on it, such as `class="mb-2"`, lands on that host. When the component must fill or stretch, or takes a `class`, style the host rather than a view inside it: see [Make the host the element](#make-the-host-the-element).

## Project into a view

```typescript title="src/app/card.ts"
import { Component } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-card',
  imports: [LYNX_ELEMENTS],
  template: `
    <view class="rounded-xl border border-border bg-card p-4">
      <ng-content />
    </view>
  `,
})
export class Card {}
```

```angular-html
<app-card>
  <text class="text-foreground">This text is projected into the card.</text>
</app-card>
```

- **Pass elements, not bare text,** into a component that projects into a `<view>`. The parent wraps its words in `<text>`.

## Project text

```typescript title="src/app/card-title.ts"
import { Component } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-card-title',
  imports: [LYNX_ELEMENTS],
  template: `
    <text class="text-lg font-semibold text-foreground">
      <ng-content />
    </text>
  `,
})
export class CardTitle {}
```

```angular-html
<app-card-title>My card title</app-card-title>

<app-card-title>
  Order
  <text class="text-muted-foreground">#1042</text>
</app-card-title>
```

- **Bare text works here,** because it lands inside the component's `<text>`.
- **Nested `<text>` styles part of the text.** The second usage renders "Order #1042" on one line, with the number muted.

## Fill the parent from the host

```typescript title="src/app/panel.ts"
import { Component } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-panel',
  imports: [LYNX_ELEMENTS],
  // The host is the element the parent lays out, so it takes the flex-1.
  host: { class: 'flex flex-1 flex-col' },
  template: `
    <scroll-view scroll-orientation="vertical" class="h-full w-full">
      <ng-content />
    </scroll-view>
  `,
})
export class Panel {}
```

- **Put sizing on the host.** A `flex-1` on an inner view does nothing if the unstyled host around it sizes to its content.
- **A component with no content needs host sizing most.** With nothing inside, its host can collapse to zero size, hiding everything in it.

## Make the host the element

```typescript title="src/app/card-title.ts"
import { Component, computed, input } from '@angular/core';
import { registerHostElement } from '@blotch/angular-lynx';

@Component({
  selector: 'app-card-title',
  host: { '[class]': 'classes()' },
  template: '<ng-content />',
})
export class CardTitle {
  readonly userClass = input('', { alias: 'class' });
  protected readonly classes = computed(
    () => `text-lg font-semibold text-foreground ${this.userClass()}`,
  );
}

// The host is a <text>, not a view around one.
registerHostElement(CardTitle, 'text');
```

```angular-html
<app-card-title class="mb-2">My card title</app-card-title>
```

- **One element, styled once.** Angular puts `class="mb-2"` on the host whatever the component does with it. With the classes bound on the host, and no `<text>` inside, the margin applies once.
- **`registerHostElement()` picks the element.** A host is a `<view>` otherwise; text has to be in a `<text>`. See [`registerHostElement()`](/api/angular-lynx/elements/host-and-native.md#registerhostelement).
- **A view-shaped component needs only the `host` binding.** Its host is already a view: bind the classes there and drop the wrapper `<view>`.
- **Other attributes land on the host too.** If a `placeholder` input is meant for an inner `<input>`, remove the host's copy with `host: { '[attr.placeholder]': 'null' }`.

## Named slots

```typescript title="src/app/badge.ts"
import { Component } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-badge',
  imports: [LYNX_ELEMENTS],
  template: `
    <text class="rounded-full bg-muted px-2 text-sm">
      <ng-content select="[icon]" />
      <ng-content />
    </text>
  `,
})
export class Badge {}
```

```angular-html
<app-badge>
  <text icon class="text-primary">★ </text>
  <text>Featured</text>
</app-badge>
```

`select` works as on the web, including inside a `<text>`.

## Conditional projection

```typescript title="src/app/expandable-label.ts"
import { Component, input } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-expandable-label',
  imports: [LYNX_ELEMENTS],
  template: `
    <text class="text-foreground">
      @if (expanded()) {
        <ng-content />
      } @else {
        <text>…</text>
      }
    </text>
  `,
})
export class ExpandableLabel {
  readonly expanded = input(true);
}
```

`@if` and `@for` work around projected content, inside a `<view>` or a `<text>`.

## Content queries

```typescript title="src/app/item-list.ts"
import { Component, ElementRef, contentChildren } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-item-list',
  imports: [LYNX_ELEMENTS],
  template: `
    <view>
      <text>Items: {{ items().length }}</text>
      <ng-content />
    </view>
  `,
})
export class ItemList {
  readonly items = contentChildren('item', { read: ElementRef });
}
```

```angular-html
<app-item-list>
  <text #item>Item A</text>
  <text #item>Item B</text>
</app-item-list>
```

`contentChild()` and `contentChildren()` find projected elements and components, as on the web. With `read: ElementRef`, you get the Lynx element, not a DOM node.

## Related

- [Elements and layout](/guide/elements/index.md): the `<text>` and layout rules
- [Content projection on angular.dev](https://angular.dev/guide/components/content-projection)
