@@ -393,15 +393,17 @@ export class ProtoElementInjector {
393393 _strategy : _ProtoElementInjectorStrategy ;
394394
395395 static create ( parent : ProtoElementInjector , index : number , bindings : List < ResolvedBinding > ,
396- firstBindingIsComponent : boolean , distanceToParent : number ) {
396+ firstBindingIsComponent : boolean , distanceToParent : number ,
397+ directiveVariableBindings : Map < string , number > ) {
397398 var bd = [ ] ;
398399
399400 ProtoElementInjector . _createDirectiveBindingData ( bindings , bd , firstBindingIsComponent ) ;
400401 if ( firstBindingIsComponent ) {
401402 ProtoElementInjector . _createViewInjectorBindingData ( bindings , bd ) ;
402403 }
403404 ProtoElementInjector . _createHostInjectorBindingData ( bindings , bd , firstBindingIsComponent ) ;
404- return new ProtoElementInjector ( parent , index , bd , distanceToParent , firstBindingIsComponent ) ;
405+ return new ProtoElementInjector ( parent , index , bd , distanceToParent , firstBindingIsComponent ,
406+ directiveVariableBindings ) ;
405407 }
406408
407409 private static _createDirectiveBindingData ( dirBindings : List < ResolvedBinding > ,
@@ -450,7 +452,8 @@ export class ProtoElementInjector {
450452 }
451453
452454 constructor ( public parent : ProtoElementInjector , public index : int , bd : List < BindingData > ,
453- public distanceToParent : number , public _firstBindingIsComponent : boolean ) {
455+ public distanceToParent : number , public _firstBindingIsComponent : boolean ,
456+ public directiveVariableBindings : Map < string , number > ) {
454457 var length = bd . length ;
455458 this . eventEmitterAccessors = ListWrapper . createFixedSize ( length ) ;
456459 this . hostActionAccessors = ListWrapper . createFixedSize ( length ) ;
@@ -693,12 +696,15 @@ export class ElementInjector extends TreeNode<ElementInjector> {
693696 }
694697
695698 onAllChangesDone ( ) : void {
696- if ( isPresent ( this . _query0 ) && this . _query0 . originator === this )
699+ if ( isPresent ( this . _query0 ) && this . _query0 . originator === this ) {
697700 this . _query0 . list . fireCallbacks ( ) ;
698- if ( isPresent ( this . _query1 ) && this . _query1 . originator === this )
701+ }
702+ if ( isPresent ( this . _query1 ) && this . _query1 . originator === this ) {
699703 this . _query1 . list . fireCallbacks ( ) ;
700- if ( isPresent ( this . _query2 ) && this . _query2 . originator === this )
704+ }
705+ if ( isPresent ( this . _query2 ) && this . _query2 . originator === this ) {
701706 this . _query2 . list . fireCallbacks ( ) ;
707+ }
702708 }
703709
704710 hydrate ( injector : Injector , host : ElementInjector , preBuiltObjects : PreBuiltObjects ) : void {
@@ -716,9 +722,22 @@ export class ElementInjector extends TreeNode<ElementInjector> {
716722 this . _checkShadowDomAppInjector ( this . _shadowDomAppInjector ) ;
717723
718724 this . _strategy . hydrate ( ) ;
725+
726+ this . _addVarBindingsToQueries ( ) ;
727+
719728 this . hydrated = true ;
720729 }
721730
731+ hasVariableBinding ( name : string ) : boolean {
732+ var vb = this . _proto . directiveVariableBindings ;
733+ return isPresent ( vb ) && MapWrapper . contains ( vb , name ) ;
734+ }
735+
736+ getVariableBinding ( name : string ) : any {
737+ var index = MapWrapper . get ( this . _proto . directiveVariableBindings , name ) ;
738+ return isPresent ( index ) ? this . getDirectiveAtIndex ( < number > index ) : this . getElementRef ( ) ;
739+ }
740+
722741 private _createShadowDomAppInjector ( componentDirective : DirectiveBinding ,
723742 appInjector : Injector ) : Injector {
724743 if ( ! ListWrapper . isEmpty ( componentDirective . resolvedAppInjectables ) ) {
@@ -752,6 +771,10 @@ export class ElementInjector extends TreeNode<ElementInjector> {
752771 return this . _proto . hostActionAccessors ;
753772 }
754773
774+ getDirectiveVariableBindings ( ) : Map < string , number > {
775+ return this . _proto . directiveVariableBindings ;
776+ }
777+
755778 getComponent ( ) : any { return this . _strategy . getComponent ( ) ; }
756779
757780 getElementRef ( ) : ElementRef {
@@ -884,6 +907,23 @@ export class ElementInjector extends TreeNode<ElementInjector> {
884907 }
885908 }
886909
910+ private _addVarBindingsToQueries ( ) : void {
911+ this . _addVarBindingsToQuery ( this . _query0 ) ;
912+ this . _addVarBindingsToQuery ( this . _query1 ) ;
913+ this . _addVarBindingsToQuery ( this . _query2 ) ;
914+ }
915+
916+ private _addVarBindingsToQuery ( queryRef : QueryRef ) : void {
917+ if ( isBlank ( queryRef ) || ! queryRef . query . isVarBindingQuery ) return ;
918+
919+ var vb = queryRef . query . varBindings ;
920+ for ( var i = 0 ; i < vb . length ; ++ i ) {
921+ if ( this . hasVariableBinding ( vb [ i ] ) ) {
922+ queryRef . list . add ( this . getVariableBinding ( vb [ i ] ) ) ;
923+ }
924+ }
925+ }
926+
887927 private _createQueryRef ( query : Query ) : void {
888928 var queryList = new QueryList < any > ( ) ;
889929 if ( isBlank ( this . _query0 ) ) {
@@ -1454,13 +1494,32 @@ class QueryRef {
14541494
14551495 visit ( inj : ElementInjector , aggregator : any [ ] ) : void {
14561496 if ( isBlank ( inj ) || ! inj . _hasQuery ( this ) ) return ;
1457- if ( inj . hasDirective ( this . query . selector ) ) {
1458- aggregator . push ( inj . get ( this . query . selector ) ) ;
1497+
1498+ if ( this . query . isVarBindingQuery ) {
1499+ this . _aggregateVariableBindings ( inj , aggregator ) ;
1500+ } else {
1501+ this . _aggregateDirective ( inj , aggregator ) ;
14591502 }
1503+
14601504 var child = inj . _head ;
14611505 while ( isPresent ( child ) ) {
14621506 this . visit ( child , aggregator ) ;
14631507 child = child . _next ;
14641508 }
14651509 }
1510+
1511+ private _aggregateVariableBindings ( inj : ElementInjector , aggregator : List < any > ) : void {
1512+ var vb = this . query . varBindings ;
1513+ for ( var i = 0 ; i < vb . length ; ++ i ) {
1514+ if ( inj . hasVariableBinding ( vb [ i ] ) ) {
1515+ aggregator . push ( inj . getVariableBinding ( vb [ i ] ) ) ;
1516+ }
1517+ }
1518+ }
1519+
1520+ private _aggregateDirective ( inj : ElementInjector , aggregator : List < any > ) : void {
1521+ if ( inj . hasDirective ( this . query . selector ) ) {
1522+ aggregator . push ( inj . get ( this . query . selector ) ) ;
1523+ }
1524+ }
14661525}
0 commit comments