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.
@paramopts
{ descendants?: boolean | undefined; read?: undefined; debugName?: string | undefined; } | undefined
@returns
Signal<LocatorT | undefined>
function contentChild<LocatorT, ReadT>(locator: string | ProviderToken<LocatorT>, opts: { descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }): Signal<ReadT | undefined>;
@paramopts
{ descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }
@returns
Signal<ReadT | undefined>
function contentChild.required<LocatorT>(locator: string | ProviderToken<LocatorT>, opts?: { descendants?: boolean | undefined; read?: undefined; debugName?: string | undefined; } | undefined): Signal<LocatorT>;
@paramopts
{ descendants?: boolean | undefined; read?: undefined; debugName?: string | undefined; } | undefined
@returns
Signal<LocatorT>
function contentChild.required<LocatorT, ReadT>(locator: string | ProviderToken<LocatorT>, opts: { descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }): Signal<ReadT>;
@paramopts
{ descendants?: boolean | undefined; read: ProviderToken<ReadT>; debugName?: string | undefined; }
@returns
Signal<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