feat(query): allow to query for TemplateRef

Part of #1989

Closes #3202
This commit is contained in:
Tobias Bosch
2015-07-22 14:24:57 -07:00
parent 5b5d31fa9a
commit 585ea5d600
5 changed files with 61 additions and 6 deletions

View File

@ -714,6 +714,10 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
}
addDirectivesMatchingQuery(query: Query, list: any[]): void {
var templateRef = this._preBuiltObjects.templateRef;
if (query.selector === TemplateRef && isPresent(templateRef)) {
list.push(templateRef);
}
this._strategy.addDirectivesMatchingQuery(query, list);
}

View File

@ -366,10 +366,13 @@ function _createProtoElementInjector(binderIndex, parentPeiWithDistance, renderE
componentDirectiveBinding, directiveBindings) {
var protoElementInjector = null;
// Create a protoElementInjector for any element that either has bindings *or* has one
// or more var- defined. Elements with a var- defined need a their own element injector
// so that, when hydrating, $implicit can be set to the element.
// or more var- defined *or* for <template> elements:
// - Elements with a var- defined need a their own element injector
// so that, when hydrating, $implicit can be set to the element.
// - <template> elements need their own ElementInjector so that we can query their TemplateRef
var hasVariables = MapWrapper.size(renderElementBinder.variableBindings) > 0;
if (directiveBindings.length > 0 || hasVariables) {
if (directiveBindings.length > 0 || hasVariables ||
isPresent(renderElementBinder.nestedProtoView)) {
var directiveVariableBindings =
createDirectiveVariableBindings(renderElementBinder, directiveBindings);
protoElementInjector =

View File

@ -28,5 +28,5 @@ export class TemplateRef {
/**
* Whether this template has a local variable with the given name
*/
hasLocal(name: string): boolean { return this._getProtoView().protoLocals.has(name); }
hasLocal(name: string): boolean { return this._getProtoView().variableBindings.has(name); }
}