Skip to content

Commit

Permalink
fix(core): require 'static' flag on queries in typings
Browse files Browse the repository at this point in the history
This commit makes the static flag on @ViewChild and @ContentChild required.

BREAKING CHANGE

Starting with v8.0, Angular requires that all @ViewChild and @ContentChild
queries have a 'static' flag specifying whether the query is 'static' or
'dynamic'. The compiler previously sorted queries automatically, but in
8.0 developers are required to explicitly specify which behavior is wanted.

@ViewChildren and @ContentChildren queries are always dynamic, and so are
unaffected.

See https://angular.io/guide/static-query-migration for more details
  • Loading branch information
alxhub committed May 23, 2019
1 parent 132c61d commit 7c62398
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/compiler/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Query {
read: any;
isViewQuery: boolean;
selector: any;
static?: boolean;
static: boolean;
}

export const createContentChildren = makeMetadataFactory<Query>(
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/metadata/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export interface Query {
read: any;
isViewQuery: boolean;
selector: any;
static?: boolean;
static: boolean;
}

/**
Expand Down Expand Up @@ -218,8 +218,8 @@ export interface ContentChildDecorator {
*
* @Annotation
*/
(selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): any;
new (selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): ContentChild;
(selector: Type<any>|Function|string, opts?: {read?: any, static: boolean}): any;
new (selector: Type<any>|Function|string, opts?: {read?: any, static: boolean}): ContentChild;
}

/**
Expand Down Expand Up @@ -350,8 +350,8 @@ export interface ViewChildDecorator {
*
* @Annotation
*/
(selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): any;
new (selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): ViewChild;
(selector: Type<any>|Function|string, opts?: {read?: any, static: boolean}): any;
new (selector: Type<any>|Function|string, opts?: {read?: any, static: boolean}): ViewChild;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/core/test/render3/jit/directive_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ describe('jit directive helper functions', () => {
descendants: false,
first: false,
isViewQuery: false,
read: undefined
read: undefined,
static: false,
})).toEqual({
propertyName: 'propName',
predicate: ['localRef'],
Expand All @@ -69,7 +70,8 @@ describe('jit directive helper functions', () => {
descendants: true,
first: true,
isViewQuery: true,
read: undefined
read: undefined,
static: false,
})).toEqual({
propertyName: 'propName',
predicate: ['foo', 'bar', 'baz'],
Expand Down
3 changes: 2 additions & 1 deletion packages/router/test/regression_integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ describe('Integration', () => {
// TODO(issue/24571): remove '!'.
@ViewChild(TemplateRef) templateRef !: TemplateRef<any>;
// TODO(issue/24571): remove '!'.
@ViewChild('container', {read: ViewContainerRef}) container !: ViewContainerRef;
@ViewChild('container', {read: ViewContainerRef, static: true})
container !: ViewContainerRef;

addLink() {
this.container.createEmbeddedView(this.templateRef, {$implicit: '/simple'});
Expand Down
10 changes: 5 additions & 5 deletions tools/public_api_guard/core/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ export declare type ContentChild = Query;
export interface ContentChildDecorator {
(selector: Type<any> | Function | string, opts?: {
read?: any;
static?: boolean;
static: boolean;
}): any;
new (selector: Type<any> | Function | string, opts?: {
read?: any;
static?: boolean;
static: boolean;
}): ContentChild;
}

Expand Down Expand Up @@ -1104,7 +1104,7 @@ export interface Query {
isViewQuery: boolean;
read: any;
selector: any;
static?: boolean;
static: boolean;
}

export declare abstract class Query {
Expand Down Expand Up @@ -1384,11 +1384,11 @@ export declare type ViewChild = Query;
export interface ViewChildDecorator {
(selector: Type<any> | Function | string, opts?: {
read?: any;
static?: boolean;
static: boolean;
}): any;
new (selector: Type<any> | Function | string, opts?: {
read?: any;
static?: boolean;
static: boolean;
}): ViewChild;
}

Expand Down

0 comments on commit 7c62398

Please sign in to comment.