Skip to content

Commit a4fd678

Browse files
committed
chore(ivy): add static flag to tree-related static queries (angular#15255)
1 parent e7489f9 commit a4fd678

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

src/cdk/tree/tree.spec.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ describe('CdkTree', () => {
6464
configureCdkTreeTestingModule([SimpleCdkTreeApp]);
6565
fixture = TestBed.createComponent(SimpleCdkTreeApp);
6666

67+
fixture.detectChanges();
68+
6769
component = fixture.componentInstance;
6870
dataSource = component.dataSource as FakeDataSource;
6971
tree = component.tree;
7072
treeElement = fixture.nativeElement.querySelector('cdk-tree');
71-
72-
fixture.detectChanges();
7373
});
7474

7575
it('with a connected data source', () => {
@@ -164,12 +164,12 @@ describe('CdkTree', () => {
164164
configureCdkTreeTestingModule([CdkTreeAppWithToggle]);
165165
fixture = TestBed.createComponent(CdkTreeAppWithToggle);
166166

167+
fixture.detectChanges();
168+
167169
component = fixture.componentInstance;
168170
dataSource = component.dataSource as FakeDataSource;
169171
tree = component.tree;
170172
treeElement = fixture.nativeElement.querySelector('cdk-tree');
171-
172-
fixture.detectChanges();
173173
});
174174

175175
it('should expand/collapse the node', () => {
@@ -250,12 +250,12 @@ describe('CdkTree', () => {
250250
configureCdkTreeTestingModule([WhenNodeCdkTreeApp]);
251251
fixture = TestBed.createComponent(WhenNodeCdkTreeApp);
252252

253+
fixture.detectChanges();
254+
253255
component = fixture.componentInstance;
254256
dataSource = component.dataSource as FakeDataSource;
255257
tree = component.tree;
256258
treeElement = fixture.nativeElement.querySelector('cdk-tree');
257-
258-
fixture.detectChanges();
259259
});
260260

261261
it('with the right data', () => {
@@ -288,13 +288,13 @@ describe('CdkTree', () => {
288288
beforeEach(() => {
289289
configureCdkTreeTestingModule([ArrayDataSourceCdkTreeApp]);
290290
fixture = TestBed.createComponent(ArrayDataSourceCdkTreeApp);
291+
fixture.detectChanges();
292+
291293

292294
component = fixture.componentInstance;
293295
dataSource = component.dataSource as FakeDataSource;
294296
tree = component.tree;
295297
treeElement = fixture.nativeElement.querySelector('cdk-tree');
296-
297-
fixture.detectChanges();
298298
});
299299

300300
it('with the right data', () => {
@@ -328,12 +328,12 @@ describe('CdkTree', () => {
328328
configureCdkTreeTestingModule([ObservableDataSourceCdkTreeApp]);
329329
fixture = TestBed.createComponent(ObservableDataSourceCdkTreeApp);
330330

331+
fixture.detectChanges();
332+
331333
component = fixture.componentInstance;
332334
dataSource = component.dataSource as FakeDataSource;
333335
tree = component.tree;
334336
treeElement = fixture.nativeElement.querySelector('cdk-tree');
335-
336-
fixture.detectChanges();
337337
});
338338

339339
it('with the right data', () => {
@@ -366,13 +366,14 @@ describe('CdkTree', () => {
366366
function createTrackByTestComponent(trackByStrategy: 'reference' | 'property' | 'index') {
367367
configureCdkTreeTestingModule([CdkTreeAppWithTrackBy]);
368368
fixture = TestBed.createComponent(CdkTreeAppWithTrackBy);
369+
fixture.detectChanges();
370+
369371
component = fixture.componentInstance;
370372
component.trackByStrategy = trackByStrategy;
371373
dataSource = component.dataSource as FakeDataSource;
372374
tree = component.tree;
373375
treeElement = fixture.nativeElement.querySelector('cdk-tree');
374376

375-
fixture.detectChanges();
376377

377378
// Each node receives an attribute 'initialIndex' the element's original place
378379
getNodes(treeElement).forEach((node: Element, index: number) => {
@@ -459,13 +460,12 @@ describe('CdkTree', () => {
459460
beforeEach(() => {
460461
configureCdkTreeTestingModule([NestedCdkTreeApp]);
461462
fixture = TestBed.createComponent(NestedCdkTreeApp);
463+
fixture.detectChanges();
462464

463465
component = fixture.componentInstance;
464466
dataSource = component.dataSource as FakeDataSource;
465467
tree = component.tree;
466468
treeElement = fixture.nativeElement.querySelector('cdk-tree');
467-
468-
fixture.detectChanges();
469469
});
470470

471471
it('with a connected data source', () => {
@@ -547,13 +547,12 @@ describe('CdkTree', () => {
547547
beforeEach(() => {
548548
configureCdkTreeTestingModule([StaticNestedCdkTreeApp]);
549549
fixture = TestBed.createComponent(StaticNestedCdkTreeApp);
550+
fixture.detectChanges();
550551

551552
component = fixture.componentInstance;
552553
dataSource = component.dataSource as FakeDataSource;
553554
tree = component.tree;
554555
treeElement = fixture.nativeElement.querySelector('cdk-tree');
555-
556-
fixture.detectChanges();
557556
});
558557

559558
it('with the right data', () => {
@@ -574,13 +573,12 @@ describe('CdkTree', () => {
574573
beforeEach(() => {
575574
configureCdkTreeTestingModule([WhenNodeNestedCdkTreeApp]);
576575
fixture = TestBed.createComponent(WhenNodeNestedCdkTreeApp);
576+
fixture.detectChanges();
577577

578578
component = fixture.componentInstance;
579579
dataSource = component.dataSource as FakeDataSource;
580580
tree = component.tree;
581581
treeElement = fixture.nativeElement.querySelector('cdk-tree');
582-
583-
fixture.detectChanges();
584582
});
585583

586584
it('with the right data', () => {
@@ -613,13 +611,12 @@ describe('CdkTree', () => {
613611
beforeEach(() => {
614612
configureCdkTreeTestingModule([NestedCdkTreeAppWithToggle]);
615613
fixture = TestBed.createComponent(NestedCdkTreeAppWithToggle);
614+
fixture.detectChanges();
616615

617616
component = fixture.componentInstance;
618617
dataSource = component.dataSource as FakeDataSource;
619618
tree = component.tree;
620619
treeElement = fixture.nativeElement.querySelector('cdk-tree');
621-
622-
fixture.detectChanges();
623620
});
624621

625622
it('should expand/collapse the node multiple times', () => {
@@ -712,13 +709,12 @@ describe('CdkTree', () => {
712709
beforeEach(() => {
713710
configureCdkTreeTestingModule([ArrayDataSourceNestedCdkTreeApp]);
714711
fixture = TestBed.createComponent(ArrayDataSourceNestedCdkTreeApp);
712+
fixture.detectChanges();
715713

716714
component = fixture.componentInstance;
717715
dataSource = component.dataSource as FakeDataSource;
718716
tree = component.tree;
719717
treeElement = fixture.nativeElement.querySelector('cdk-tree');
720-
721-
fixture.detectChanges();
722718
});
723719

724720
it('with the right data', () => {
@@ -749,13 +745,12 @@ describe('CdkTree', () => {
749745
beforeEach(() => {
750746
configureCdkTreeTestingModule([ObservableDataSourceNestedCdkTreeApp]);
751747
fixture = TestBed.createComponent(ObservableDataSourceNestedCdkTreeApp);
748+
fixture.detectChanges();
752749

753750
component = fixture.componentInstance;
754751
dataSource = component.dataSource as FakeDataSource;
755752
tree = component.tree;
756753
treeElement = fixture.nativeElement.querySelector('cdk-tree');
757-
758-
fixture.detectChanges();
759754
});
760755

761756
it('with the right data', () => {
@@ -786,15 +781,15 @@ describe('CdkTree', () => {
786781
function createTrackByTestComponent(trackByStrategy: 'reference' | 'property' | 'index') {
787782
configureCdkTreeTestingModule([NestedCdkTreeAppWithTrackBy]);
788783
fixture = TestBed.createComponent(NestedCdkTreeAppWithTrackBy);
784+
fixture.detectChanges();
785+
789786
component = fixture.componentInstance;
790787
component.trackByStrategy = trackByStrategy;
791788
dataSource = component.dataSource as FakeDataSource;
792789

793790
tree = component.tree;
794791
treeElement = fixture.nativeElement.querySelector('cdk-tree');
795792

796-
fixture.detectChanges();
797-
798793
// Each node receives an attribute 'initialIndex' the element's original place
799794
getNodes(treeElement).forEach((node: Element, index: number) => {
800795
node.setAttribute('initialIndex', index.toString());
@@ -935,13 +930,12 @@ describe('CdkTree', () => {
935930
beforeEach(() => {
936931
configureCdkTreeTestingModule([DepthNestedCdkTreeApp]);
937932
fixture = TestBed.createComponent(DepthNestedCdkTreeApp);
933+
fixture.detectChanges();
938934

939935
component = fixture.componentInstance;
940936
dataSource = component.dataSource as FakeDataSource;
941937
tree = component.tree;
942938
treeElement = fixture.nativeElement.querySelector('cdk-tree');
943-
944-
fixture.detectChanges();
945939
});
946940

947941
it('should have correct depth for nested tree', () => {

src/cdk/tree/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class CdkTree<T>
9999
@Input() trackBy: TrackByFunction<T>;
100100

101101
// Outlets within the tree's template where the dataNodes will be inserted.
102-
@ViewChild(CdkTreeNodeOutlet) _nodeOutlet: CdkTreeNodeOutlet;
102+
@ViewChild(CdkTreeNodeOutlet, {static: true}) _nodeOutlet: CdkTreeNodeOutlet;
103103

104104
/** The tree node template for the tree */
105105
@ContentChildren(CdkTreeNodeDef) _nodeDefs: QueryList<CdkTreeNodeDef<T>>;

src/lib/tree/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ import {MatTreeNodeOutlet} from './outlet';
2929
})
3030
export class MatTree<T> extends CdkTree<T> {
3131
// Outlets within the tree's template where the dataNodes will be inserted.
32-
@ViewChild(MatTreeNodeOutlet) _nodeOutlet: MatTreeNodeOutlet;
32+
@ViewChild(MatTreeNodeOutlet, {static: true}) _nodeOutlet: MatTreeNodeOutlet;
3333
}

0 commit comments

Comments
 (0)