feat(core): add support for @ContentChild and @ViewChild

Closes #4251
This commit is contained in:
vsavkin
2015-09-19 18:39:35 -07:00
committed by Victor Savkin
parent 2e9de0b169
commit c2a60f1624
8 changed files with 313 additions and 23 deletions

View File

@ -10,11 +10,13 @@ import {
HostBindingMetadata,
HostListenerMetadata,
ContentChildrenMetadata,
ViewChildrenMetadata
ViewChildrenMetadata,
ContentChildMetadata,
ViewChildMetadata
} from 'angular2/src/core/metadata';
import {reflector} from 'angular2/src/core/reflection/reflection';
/**
/*
* Resolve a `Type` for {@link DirectiveMetadata}.
*
* This interface can be overridden by the application developer to create custom behavior.
@ -86,6 +88,14 @@ export class DirectiveResolver {
if (a instanceof ViewChildrenMetadata) {
queries[propName] = a;
}
if (a instanceof ContentChildMetadata) {
queries[propName] = a;
}
if (a instanceof ViewChildMetadata) {
queries[propName] = a;
}
});
});
return this._merge(dm, properties, events, host, queries);

View File

@ -967,7 +967,11 @@ export class QueryRef {
// TODO delete the check once only field queries are supported
if (isPresent(this.dirIndex)) {
var dir = this.originator.getDirectiveAtIndex(this.dirIndex);
this.setter(dir, this.list);
if (this.query.first) {
this.setter(dir, this.list.length > 0 ? this.list.first : null);
} else {
this.setter(dir, this.list);
}
}
}