Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

viewChildren

Initializes a view children query.

See more...

      
      viewChildren(locator: string | ProviderToken<LocatorT>): Signal<ReadonlyArray<LocatorT>>
    
Parameters
locator string | ProviderToken<LocatorT>
Returns

Signal<ReadonlyArray<LocatorT>>


      
      viewChildren(locator: string | ProviderToken<LocatorT>, opts: { read: ProviderToken<ReadT>; }): Signal<ReadonlyArray<ReadT>>
    
Parameters
locator string | ProviderToken<LocatorT>
opts object
Returns

Signal<ReadonlyArray<ReadT>>

Description

Query results are represented as a signal of a read-only collection containing all matched elements.

Further information is available in the Usage Notes...

Usage notes

Create a children query in your component by declaring a class field and initializing it with the viewChildren() function.

      
      @Component({...})
export class TestComponent {
  divEls = viewChildren<ElementRef>('el');   // Signal<ReadonlyArray<ElementRef>>
}