Spec-Zone.ru › Angular

contentChildren

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

Результаты запроса представлены в виде сигнала с доступной только для чтения коллекцией, содержащей все совпавшие элементы.

Ссылки на дочерние компоненты с помощью запросовЗапросы содержимого

API

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

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

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

@Component({...})
export class TestComponent {
  headerEl = contentChildren<ElementRef>('h');   // Signal<ReadonlyArray<ElementRef>>
}

Примечание: по умолчанию descendants имеет значение false, а это значит, что запрос не будет проходить по всем потомкам в том же шаблоне.

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/contentChildren

Spec-Zone.ru

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