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