@@ -25,8 +25,8 @@ import {unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
25
25
import { TContainerNode , TElementContainerNode , TElementNode , TNode , TNodeType , unusedValueExportToPlacateAjd as unused3 } from './interfaces/node' ;
26
26
import { LQueries , unusedValueExportToPlacateAjd as unused4 } from './interfaces/query' ;
27
27
import { CONTENT_QUERIES , HEADER_OFFSET , LView , QUERIES , TVIEW , TView } from './interfaces/view' ;
28
- import { getCurrentQueryIndex , getIsParent , getLView , isCreationMode , setCurrentQueryIndex } from './state' ;
29
- import { loadInternal } from './util/view_utils' ;
28
+ import { getCurrentQueryIndex , getIsParent , getLView , getPreviousOrParentTNode , isCreationMode , setCurrentQueryIndex } from './state' ;
29
+ import { isContentQueryHost , loadInternal } from './util/view_utils' ;
30
30
import { createElementRef , createTemplateRef } from './view_engine_compatibility' ;
31
31
32
32
const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 ;
@@ -92,7 +92,7 @@ class LQuery<T> {
92
92
export class LQueries_ implements LQueries {
93
93
constructor (
94
94
public parent : LQueries_ | null , private shallow : LQuery < any > | null ,
95
- private deep : LQuery < any > | null ) { }
95
+ private deep : LQuery < any > | null , public nodeIndex : number = - 1 ) { }
96
96
97
97
track < T > ( queryList : QueryList < T > , predicate : Type < T > | string [ ] , descend ?: boolean , read ?: Type < T > ) :
98
98
void {
@@ -103,7 +103,11 @@ export class LQueries_ implements LQueries {
103
103
}
104
104
}
105
105
106
- clone ( ) : LQueries { return new LQueries_ ( this , null , this . deep ) ; }
106
+ clone ( tNode : TNode ) : LQueries {
107
+ return this . shallow !== null || isContentQueryHost ( tNode ) ?
108
+ new LQueries_ ( this , null , this . deep , tNode . index ) :
109
+ this ;
110
+ }
107
111
108
112
container ( ) : LQueries | null {
109
113
const shallowResults = copyQueriesToContainer ( this . shallow ) ;
@@ -352,11 +356,11 @@ type QueryList_<T> = QueryList<T>& {_valuesTree: any[], _static: boolean};
352
356
*/
353
357
function createQueryListInLView < T > (
354
358
// TODO: "read" should be an AbstractType (FW-486)
355
- lView : LView , predicate : Type < any > | string [ ] , descend : boolean , read : any ,
356
- isStatic : boolean ) : QueryList < T > {
359
+ lView : LView , predicate : Type < any > | string [ ] , descend : boolean , read : any , isStatic : boolean ,
360
+ nodeIndex : number ) : QueryList < T > {
357
361
ngDevMode && assertPreviousIsParent ( getIsParent ( ) ) ;
358
362
const queryList = new QueryList < T > ( ) as QueryList_ < T > ;
359
- const queries = lView [ QUERIES ] || ( lView [ QUERIES ] = new LQueries_ ( null , null , null ) ) ;
363
+ const queries = lView [ QUERIES ] || ( lView [ QUERIES ] = new LQueries_ ( null , null , null , nodeIndex ) ) ;
360
364
queryList . _valuesTree = [ ] ;
361
365
queryList . _static = isStatic ;
362
366
queries . track ( queryList , predicate , descend , read ) ;
@@ -430,7 +434,7 @@ function viewQueryInternal<T>(
430
434
}
431
435
const index = getCurrentQueryIndex ( ) ;
432
436
const queryList : QueryList < T > =
433
- createQueryListInLView < T > ( lView , predicate , descend , read , isStatic ) ;
437
+ createQueryListInLView < T > ( lView , predicate , descend , read , isStatic , - 1 ) ;
434
438
store ( index - HEADER_OFFSET , queryList ) ;
435
439
setCurrentQueryIndex ( index + 1 ) ;
436
440
return queryList ;
@@ -465,16 +469,18 @@ export function ɵɵcontentQuery<T>(
465
469
read : any ) : QueryList < T > {
466
470
const lView = getLView ( ) ;
467
471
const tView = lView [ TVIEW ] ;
468
- return contentQueryInternal ( lView , tView , directiveIndex , predicate , descend , read , false ) ;
472
+ const tNode = getPreviousOrParentTNode ( ) ;
473
+ return contentQueryInternal (
474
+ lView , tView , directiveIndex , predicate , descend , read , false , tNode . index ) ;
469
475
}
470
476
471
477
function contentQueryInternal < T > (
472
478
lView : LView , tView : TView , directiveIndex : number , predicate : Type < any > | string [ ] ,
473
479
descend : boolean ,
474
480
// TODO(FW-486): "read" should be an AbstractType
475
- read : any , isStatic : boolean ) : QueryList < T > {
481
+ read : any , isStatic : boolean , nodeIndex : number ) : QueryList < T > {
476
482
const contentQuery : QueryList < T > =
477
- createQueryListInLView < T > ( lView , predicate , descend , read , isStatic ) ;
483
+ createQueryListInLView < T > ( lView , predicate , descend , read , isStatic , nodeIndex ) ;
478
484
( lView [ CONTENT_QUERIES ] || ( lView [ CONTENT_QUERIES ] = [ ] ) ) . push ( contentQuery ) ;
479
485
if ( tView . firstTemplatePass ) {
480
486
const tViewContentQueries = tView . contentQueries || ( tView . contentQueries = [ ] ) ;
@@ -505,7 +511,8 @@ export function ɵɵstaticContentQuery<T>(
505
511
read : any ) : void {
506
512
const lView = getLView ( ) ;
507
513
const tView = lView [ TVIEW ] ;
508
- contentQueryInternal ( lView , tView , directiveIndex , predicate , descend , read , true ) ;
514
+ const tNode = getPreviousOrParentTNode ( ) ;
515
+ contentQueryInternal ( lView , tView , directiveIndex , predicate , descend , read , true , tNode . index ) ;
509
516
tView . staticContentQueries = true ;
510
517
}
511
518
0 commit comments