Spec-Zone.ru › Angular

contentChild

Инициализирует запрос к дочернему элементу содержимого. Для запросов, которые всегда должны находить соответствие, рассмотрите возможность использования contentChild.required.

API

function contentChild<LocatorT>(locator, opts?);
function contentChild<LocatorT, ReadT>(locator, opts);

function contentChild.required<LocatorT>(locator, opts?);
function contentChild.required<LocatorT, ReadT>(locator, opts);
function contentChild<LocatorT>(locator: string | ProviderToken<LocatorT>, opts?: { descendants?: boolean | undefined; read?: undefined; debugName?: string | undefined; } | undefined): Signal<LocatorT | undefined>;

Инициализирует запрос к дочернему элементу содержимого.

Для запросов, которые всегда должны находить соответствие, рассмотрите возможность использования contentChild.required.

@paramlocatorstring | ProviderToken<LocatorT>
@paramopts{ descendants?: boolean | undefined; read?: undefined; debugName?: string | undefined; } | undefined
@returnsSignal<LocatorT | undefined>
function contentChild<LocatorT, ReadT>(locator: string | ProviderToken<LocatorT>, opts: { descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }): Signal<ReadT | undefined>;
@paramlocatorstring | ProviderToken<LocatorT>
@paramopts{ descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }
@returnsSignal<ReadT | undefined>
function contentChild.required<LocatorT>(locator: string | ProviderToken<LocatorT>, opts?: { descendants?: boolean | undefined; read?: undefined; debugName?: string | undefined; } | undefined): Signal<LocatorT>;
@paramlocatorstring | ProviderToken<LocatorT>
@paramopts{ descendants?: boolean | undefined; read?: undefined; debugName?: string | undefined; } | undefined
@returnsSignal<LocatorT>
function contentChild.required<LocatorT, ReadT>(locator: string | ProviderToken<LocatorT>, opts: { descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }): Signal<ReadT>;
@paramlocatorstring | ProviderToken<LocatorT>
@paramopts{ descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }
@returnsSignal<ReadT>

Примечания по использованию

Создайте запрос к дочернему элементу в компоненте, объявив поле класса и инициализировав его функцией contentChild().

@Component({...})
export class Card {
  headerEl = contentChild<ElementRef>('h');                    // Signal<ElementRef|undefined>
  headerElElRequired = contentChild.required<ElementRef>('h'); // Signal<ElementRef>
  header = contentChild(MyHeader);                             // Signal<MyHeader|undefined>
  headerRequired = contentChild.required(MyHeader);            // Signal<MyHeader>
}

ПРИМЕЧАНИЕ: По умолчанию descendants имеет значение true, то есть запрос будет обходить всех потомков в том же шаблоне.

Super-powered by Google ©2010–2025.
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
https://angular.dev/api/core/contentChild

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API