W3cubDocs

/Angular

By

class experimental

Predicates for use with DebugElement's query functions.

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

Static Methods

all()

Match all elements.

static all(): Predicate<DebugElement>

Parameters

There are no parameters.

Returns

Predicate<DebugElement>

Example

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

Match elements by the given CSS selector.

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

Parameters

selector

Type: string.

Returns

Predicate<DebugElement>

Example

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

Match elements that have the given directive present.

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

Parameters

type

Type: Type.

Returns

Predicate<DebugElement>

Example

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

© 2010–2018 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/platform-browser/By