diff --git a/packages/core/test/acceptance/query_spec.ts b/packages/core/test/acceptance/query_spec.ts index c269578e39..12a75203a1 100644 --- a/packages/core/test/acceptance/query_spec.ts +++ b/packages/core/test/acceptance/query_spec.ts @@ -177,7 +177,7 @@ describe('query logic', () => { it('should support ViewChild query inherited from undecorated superclasses', () => { class MyComp { - @ViewChild('foo') foo: any; + @ViewChild('foo', {static: false}) foo: any; } @Component({selector: 'sub-comp', template: '
'}) @@ -193,7 +193,7 @@ describe('query logic', () => { it('should support ViewChild query inherited from undecorated grand superclasses', () => { class MySuperComp { - @ViewChild('foo') foo: any; + @ViewChild('foo', {static: false}) foo: any; } class MyComp extends MySuperComp {} @@ -493,7 +493,7 @@ describe('query logic', () => { it('should support ContentChild query inherited from undecorated superclasses', () => { class MyComp { - @ContentChild('foo') foo: any; + @ContentChild('foo', {static: false}) foo: any; } @Component({selector: 'sub-comp', template: ''}) @@ -502,7 +502,7 @@ describe('query logic', () => { @Component({template: '
'}) class App { - @ViewChild(SubComp) subComp !: SubComp; + @ViewChild(SubComp, {static: false}) subComp !: SubComp; } TestBed.configureTestingModule({declarations: [App, SubComp]}); @@ -514,7 +514,7 @@ describe('query logic', () => { it('should support ContentChild query inherited from undecorated grand superclasses', () => { class MySuperComp { - @ContentChild('foo') foo: any; + @ContentChild('foo', {static: false}) foo: any; } class MyComp extends MySuperComp {} @@ -525,7 +525,7 @@ describe('query logic', () => { @Component({template: '
'}) class App { - @ViewChild(SubComp) subComp !: SubComp; + @ViewChild(SubComp, {static: false}) subComp !: SubComp; } TestBed.configureTestingModule({declarations: [App, SubComp]}); @@ -557,7 +557,7 @@ describe('query logic', () => { ` }) class App { - @ViewChild(SubComp) subComp !: SubComp; + @ViewChild(SubComp, {static: false}) subComp !: SubComp; } TestBed.configureTestingModule({declarations: [App, SubComp, SomeDir]}); @@ -592,7 +592,7 @@ describe('query logic', () => { ` }) class App { - @ViewChild(SubComp) subComp !: SubComp; + @ViewChild(SubComp, {static: false}) subComp !: SubComp; } TestBed.configureTestingModule({declarations: [App, SubComp, SomeDir]}); @@ -806,9 +806,10 @@ describe('query logic', () => { `, }) class TestComponent { - @ViewChild(ViewContainerManipulatorDirective) vc !: ViewContainerManipulatorDirective; - @ViewChild('tpl1') tpl1 !: TemplateRef; - @ViewChild('tpl2') tpl2 !: TemplateRef; + @ViewChild(ViewContainerManipulatorDirective, {static: false}) + vc !: ViewContainerManipulatorDirective; + @ViewChild('tpl1', {static: false}) tpl1 !: TemplateRef; + @ViewChild('tpl2', {static: false}) tpl2 !: TemplateRef; @ViewChildren('foo') query !: QueryList; } @@ -878,9 +879,9 @@ describe('query logic', () => { `, }) class TestComponent { - @ViewChild('tpl') tpl !: TemplateRef; - @ViewChild('vi0') vi0 !: ViewContainerManipulatorDirective; - @ViewChild('vi1') vi1 !: ViewContainerManipulatorDirective; + @ViewChild('tpl', {static: false}) tpl !: TemplateRef; + @ViewChild('vi0', {static: false}) vi0 !: ViewContainerManipulatorDirective; + @ViewChild('vi1', {static: false}) vi1 !: ViewContainerManipulatorDirective; @ViewChildren('foo') query !: QueryList; } @@ -963,8 +964,8 @@ function initWithTemplate(compType: Type, template: string) { @Component({selector: 'local-ref-query-component', template: ''}) class QueryComp { - @ViewChild('viewQuery') viewChild !: any; - @ContentChild('contentQuery') contentChild !: any; + @ViewChild('viewQuery', {static: false}) viewChild !: any; + @ContentChild('contentQuery', {static: false}) contentChild !: any; @ViewChildren('viewQuery') viewChildren !: QueryList; @ContentChildren('contentQuery') contentChildren !: QueryList; diff --git a/packages/core/test/linker/query_integration_spec.ts b/packages/core/test/linker/query_integration_spec.ts index 1f68c34363..41378a6245 100644 --- a/packages/core/test/linker/query_integration_spec.ts +++ b/packages/core/test/linker/query_integration_spec.ts @@ -752,7 +752,7 @@ describe('Query API', () => { class AutoProjecting { // TODO(issue/24571): // remove '!'. - @ContentChild(TemplateRef) + @ContentChild(TemplateRef, {static: false}) content !: TemplateRef; // TODO(issue/24571): @@ -784,7 +784,7 @@ describe('Query API', () => { class AutoProjecting { // TODO(issue/24571): // remove '!'. - @ContentChild(TemplateRef) + @ContentChild(TemplateRef, {static: false}) content !: TemplateRef; // TODO(issue/24571): @@ -839,7 +839,7 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked { // TODO(issue/24571): remove '!'. _child !: TextDirective; - @ContentChild(TextDirective) + @ContentChild(TextDirective, {static: false}) set child(value) { this._child = value; this.logs.push(['setter', value ? value.text : null]); @@ -856,7 +856,7 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked { @Directive({selector: '[directive-needs-content-child]'}) class DirectiveNeedsContentChild { // TODO(issue/24571): remove '!'. - @ContentChild(TextDirective) child !: TextDirective; + @ContentChild(TextDirective, {static: false}) child !: TextDirective; } @Component({selector: 'needs-view-child', template: `
`}) @@ -867,7 +867,7 @@ class NeedsViewChild implements AfterViewInit, AfterViewChecked { // TODO(issue/24571): remove '!'. _child !: TextDirective; - @ViewChild(TextDirective) + @ViewChild(TextDirective, {static: false}) set child(value) { this._child = value; this.logs.push(['setter', value ? value.text : null]); @@ -896,9 +896,9 @@ function createTestCmpAndDetectChanges(type: Type, template: string): Comp @Component({selector: 'needs-static-content-view-child', template: `
`}) class NeedsStaticContentAndViewChild { // TODO(issue/24571): remove '!'. - @ContentChild(TextDirective) contentChild !: TextDirective; + @ContentChild(TextDirective, {static: true}) contentChild !: TextDirective; // TODO(issue/24571): remove '!'. - @ViewChild(TextDirective) viewChild !: TextDirective; + @ViewChild(TextDirective, {static: true}) viewChild !: TextDirective; } @Directive({selector: '[dir]'}) @@ -917,13 +917,13 @@ class NeedsQuery { @Component({selector: 'needs-four-queries', template: ''}) class NeedsFourQueries { // TODO(issue/24571): remove '!'. - @ContentChild(TextDirective) query1 !: TextDirective; + @ContentChild(TextDirective, {static: false}) query1 !: TextDirective; // TODO(issue/24571): remove '!'. - @ContentChild(TextDirective) query2 !: TextDirective; + @ContentChild(TextDirective, {static: false}) query2 !: TextDirective; // TODO(issue/24571): remove '!'. - @ContentChild(TextDirective) query3 !: TextDirective; + @ContentChild(TextDirective, {static: false}) query3 !: TextDirective; // TODO(issue/24571): remove '!'. - @ContentChild(TextDirective) query4 !: TextDirective; + @ContentChild(TextDirective, {static: false}) query4 !: TextDirective; } @Component({ @@ -1025,9 +1025,9 @@ class NeedsTpl { {selector: 'needs-named-tpl', template: '
shadow
'}) class NeedsNamedTpl { // TODO(issue/24571): remove '!'. - @ViewChild('tpl') viewTpl !: TemplateRef; + @ViewChild('tpl', {static: true}) viewTpl !: TemplateRef; // TODO(issue/24571): remove '!'. - @ContentChild('tpl') contentTpl !: TemplateRef; + @ContentChild('tpl', {static: true}) contentTpl !: TemplateRef; constructor(public vc: ViewContainerRef) {} } @@ -1042,9 +1042,10 @@ class NeedsContentChildrenWithRead { @Component({selector: 'needs-content-child-read', template: ''}) class NeedsContentChildWithRead { // TODO(issue/24571): remove '!'. - @ContentChild('q', {read: TextDirective}) textDirChild !: TextDirective; + @ContentChild('q', {read: TextDirective, static: false}) textDirChild !: TextDirective; // TODO(issue/24571): remove '!'. - @ContentChild('nonExisting', {read: TextDirective}) nonExistingVar !: TextDirective; + @ContentChild('nonExisting', {read: TextDirective, static: false}) + nonExistingVar !: TextDirective; } @Component({selector: 'needs-content-children-shallow', template: ''}) @@ -1059,7 +1060,7 @@ class NeedsContentChildrenShallow { }) class NeedsContentChildTemplateRef { // TODO(issue/24571): remove '!'. - @ContentChild(TemplateRef) templateRef !: TemplateRef; + @ContentChild(TemplateRef, {static: true}) templateRef !: TemplateRef; } @Component({ @@ -1088,19 +1089,20 @@ class NeedsViewChildrenWithRead { }) class NeedsViewChildWithRead { // TODO(issue/24571): remove '!'. - @ViewChild('q', {read: TextDirective}) textDirChild !: TextDirective; + @ViewChild('q', {read: TextDirective, static: false}) textDirChild !: TextDirective; // TODO(issue/24571): remove '!'. - @ViewChild('nonExisting', {read: TextDirective}) nonExistingVar !: TextDirective; + @ViewChild('nonExisting', {read: TextDirective, static: false}) nonExistingVar !: TextDirective; } @Component({selector: 'needs-viewcontainer-read', template: '
'}) class NeedsViewContainerWithRead { // TODO(issue/24571): remove '!'. - @ViewChild('q', {read: ViewContainerRef}) vc !: ViewContainerRef; + @ViewChild('q', {read: ViewContainerRef, static: false}) vc !: ViewContainerRef; // TODO(issue/24571): remove '!'. - @ViewChild('nonExisting', {read: ViewContainerRef}) nonExistingVar !: ViewContainerRef; + @ViewChild('nonExisting', {read: ViewContainerRef, static: false}) + nonExistingVar !: ViewContainerRef; // TODO(issue/24571): remove '!'. - @ContentChild(TemplateRef) template !: TemplateRef; + @ContentChild(TemplateRef, {static: true}) template !: TemplateRef; createView() { this.vc.createEmbeddedView(this.template); } } @@ -1123,10 +1125,10 @@ class MyCompBroken0 { @Component({selector: 'manual-projecting', template: '
'}) class ManualProjecting { // TODO(issue/24571): remove '!'. - @ContentChild(TemplateRef) template !: TemplateRef; + @ContentChild(TemplateRef, {static: true}) template !: TemplateRef; // TODO(issue/24571): remove '!'. - @ViewChild('vc', {read: ViewContainerRef}) + @ViewChild('vc', {read: ViewContainerRef, static: false}) vc !: ViewContainerRef; // TODO(issue/24571): remove '!'. diff --git a/packages/core/test/metadata/di_spec.ts b/packages/core/test/metadata/di_spec.ts index 733328e53c..408f2ac67d 100644 --- a/packages/core/test/metadata/di_spec.ts +++ b/packages/core/test/metadata/di_spec.ts @@ -83,13 +83,13 @@ class Simple { @Component({selector: 'view-child-type-selector', template: ''}) class ViewChildTypeSelectorComponent { // TODO(issue/24571): remove '!'. - @ViewChild(Simple) child !: Simple; + @ViewChild(Simple, {static: false}) child !: Simple; } @Component({selector: 'view-child-string-selector', template: ''}) class ViewChildStringSelectorComponent { // TODO(issue/24571): remove '!'. - @ViewChild('child') child !: ElementRef; + @ViewChild('child', {static: false}) child !: ElementRef; } @Component({selector: 'view-children-type-selector', template: ''})