angular2
Version:
Angular 2 - a web framework for modern web apps
40 lines (39 loc) • 1.15 kB
JavaScript
import { isPresent } from 'angular2/src/facade/lang';
import { DOM } from 'angular2/src/platform/dom/dom_adapter';
/**
* Predicates for use with {@link DebugElement}'s query functions.
*/
export class By {
/**
* Match all elements.
*
* ## Example
*
* {@example platform/dom/debug/ts/by/by.ts region='by_all'}
*/
static all() { return (debugElement) => true; }
/**
* Match elements by the given CSS selector.
*
* ## Example
*
* {@example platform/dom/debug/ts/by/by.ts region='by_css'}
*/
static css(selector) {
return (debugElement) => {
return isPresent(debugElement.nativeElement) ?
DOM.elementMatches(debugElement.nativeElement, selector) :
false;
};
}
/**
* Match elements that have the given directive present.
*
* ## Example
*
* {@example platform/dom/debug/ts/by/by.ts region='by_directive'}
*/
static directive(type) {
return (debugElement) => { return debugElement.providerTokens.indexOf(type) !== -1; };
}
}