This is the archived documentation for Angular v5. Please visit angular.io to see documentation for the current version of Angular.

By

npm Package @angular/platform-browser
Module import { By } from '@angular/platform-browser';
Source platform-browser/src/dom/debug/by.ts

Overview

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

Description

Predicates for use with DebugElement's query functions.

Static Members

      
      static all(): Predicate<DebugElement>
    

Match all elements.

Example

      
      debugElement.query(By.all());
    

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

Match elements by the given CSS selector.

Example

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

      
      static directive(type: Type<any>): Predicate<DebugElement>
    

Match elements that have the given directive present.

Example

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