Files
Angular-Cn/modules/@angular/platform-browser/src/dom/debug/by.ts
T

46 lines
1.2 KiB
TypeScript
Raw Normal View History

import {DebugElement} from '@angular/core';
2016-05-31 15:22:59 -07:00
import {Type, isPresent} from '../../facade/lang';
import {Predicate} from '../../facade/collection';
import {getDOM} from '../../dom/dom_adapter';
2015-11-17 15:24:36 -08:00
/**
* Predicates for use with {@link DebugElement}'s query functions.
*/
2015-11-17 15:24:36 -08:00
export class By {
/**
* Match all elements.
*
* ## Example
*
* {@example platform/dom/debug/ts/by/by.ts region='by_all'}
*/
static all(): Predicate<DebugElement> { return (debugElement) => true; }
2015-11-17 15:24:36 -08:00
/**
* Match elements by the given CSS selector.
*
* ## Example
*
* {@example platform/dom/debug/ts/by/by.ts region='by_css'}
*/
2015-11-17 15:24:36 -08:00
static css(selector: string): Predicate<DebugElement> {
return (debugElement) => {
return isPresent(debugElement.nativeElement) ?
getDOM().elementMatches(debugElement.nativeElement, selector) :
false;
2015-11-17 15:24:36 -08:00
};
}
/**
* Match elements that have the given directive present.
*
* ## Example
*
* {@example platform/dom/debug/ts/by/by.ts region='by_directive'}
*/
2015-11-17 15:24:36 -08:00
static directive(type: Type): Predicate<DebugElement> {
return (debugElement) => { return debugElement.providerTokens.indexOf(type) !== -1; };
2015-11-17 15:24:36 -08:00
}
}