feat(query): adds support for descendants and more list apis.

Additional clean up of query code.

Closes: #1935

BREAKING CHANGE:
By default Query only queries direct children.
This commit is contained in:
Rado Kirov
2015-06-10 17:08:22 -07:00
parent ca09701343
commit 355ab5b3a6
8 changed files with 150 additions and 116 deletions
@@ -231,14 +231,13 @@ import {DEFAULT} from 'angular2/change_detection';
*
* ### Injecting a live collection of descendant directives
*
* Note: This is will be implemented in later release. ()
*
* Similar to `@Query` above, but also includes the children of the child elements.
* By passing the descendant flag to `@Query` above, we can include the children of the child
* elements.
*
* ```
* @Directive({ selector: '[my-directive]' })
* class MyDirective {
* constructor(@QueryDescendents(Dependency) dependencies:QueryList<Dependency>) {
* constructor(@Query(Dependency, {descendants: true}) dependencies:QueryList<Dependency>) {
* }
* }
* ```
@@ -1,5 +1,6 @@
import {CONST, stringify} from 'angular2/src/facade/lang';
import {CONST, stringify, isPresent} from 'angular2/src/facade/lang';
import {DependencyAnnotation} from 'angular2/src/di/annotations_impl';
import {resolveForwardRef} from 'angular2/di';
/**
* Specifies that a constant attribute value should be injected.
@@ -53,6 +54,13 @@ export class Attribute extends DependencyAnnotation {
*/
@CONST()
export class Query extends DependencyAnnotation {
constructor(public directive: any) { super(); }
descendants: boolean;
constructor(private _directive: any, {descendants = false}: {descendants?: boolean} = {}) {
super();
this.descendants = descendants;
}
get directive() { return resolveForwardRef(this._directive); }
toString() { return `@Query(${stringify(this.directive)})`; }
}