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.

By

Predicates for use with DebugElement's query functions.

      
      class By {
  static all(): Predicate<DebugNode>
  static css(selector: string): Predicate<DebugElement>
  static directive(type: Type<any>): Predicate<DebugNode>
}
    

Static methods

Match all nodes.

      
      static all(): Predicate<DebugNode>
    
Parameters

There are no parameters.

Returns

Predicate<DebugNode>

Usage Notes

Example
      
      debugElement.query(By.all());
    

Match elements by the given CSS selector.

      
      static css(selector: string): Predicate<DebugElement>
    
Parameters
selector string
Returns

Predicate<DebugElement>

Usage Notes

Example
      
      debugElement.query(By.css('[attribute]'));
    

Match nodes that have the given directive present.

      
      static directive(type: Type<any>): Predicate<DebugNode>
    
Parameters
type Type<any>
Returns

Predicate<DebugNode>

Usage Notes

Example
      
      debugElement.query(By.directive(MyDirective));