angular-docs-cn/tools
Kara Erickson 19afb791b4 feat(core): allow users to define timing of ViewChild/ContentChild queries (#28810)
Prior to this commit, the timing of `ViewChild`/`ContentChild` query
resolution depended on the results of each query. If any results
for a particular query were nested inside embedded views (e.g.
*ngIfs), that query would be resolved after change detection ran.
Otherwise, the query would be resolved as soon as nodes were created.

This inconsistency in resolution timing had the potential to cause
confusion because query results would sometimes be available in
ngOnInit, but sometimes wouldn't be available until ngAfterContentInit
or ngAfterViewInit. Code depending on a query result could suddenly
stop working as soon as an *ngIf or an *ngFor was added to the template.

With this commit, users can dictate when they want a particular
`ViewChild` or `ContentChild` query to be resolved with the `static`
flag. For example, one can mark a particular query as `static: false`
to ensure change detection always runs before its results are set:

```ts
@ContentChild('foo', {static: false}) foo !: ElementRef;
```

This means that even if there isn't a query result wrapped in an
*ngIf or an *ngFor now, adding one to the template later won't change
the timing of the query resolution and potentially break your component.

Similarly, if you know that your query needs to be resolved earlier
(e.g. you need results in an ngOnInit hook), you can mark it as
`static: true`.

```ts
@ViewChild(TemplateRef, {static: true}) foo !: TemplateRef;
```

Note: this means that your component will not support *ngIf results.

If you do not supply a `static` option when creating your `ViewChild` or
`ContentChild` query, the default query resolution timing will kick in.

Note: This new option only applies to `ViewChild` and `ContentChild`
queries, not `ViewChildren` or `ContentChildren` queries, as those types
already resolve after CD runs.

PR Close #28810
2019-02-19 12:56:25 -08:00
..
build build: remove obsolete files (#26471) 2018-10-23 08:57:41 -07:00
cjs-jasmine refactor(ivy): run the compiler compliance tests against ngtsc (#24862) 2018-07-20 11:48:36 -07:00
gulp-tasks build: fix `validate-commit-message` on Windows (#28780) 2019-02-19 12:37:57 -08:00
http-server style: format .bzl files with buildifier (#23544) 2018-08-08 13:12:07 -07:00
material-ci fix(ivy): rethrow event handler errors in tests (#28707) 2019-02-14 19:26:56 +00:00
ngcontainer build: use bazel version from node modules (#26691) 2018-10-30 16:19:13 -04:00
npm build(bazel): replace yarn_install(name = "npm") with @npm local_reporsitory() to speed up build (#27469) 2018-12-05 10:48:19 -08:00
npm_workspace build(bazel): replace yarn_install(name = "npm") with @npm local_reporsitory() to speed up build (#27469) 2018-12-05 10:48:19 -08:00
public_api_guard feat(core): allow users to define timing of ViewChild/ContentChild queries (#28810) 2019-02-19 12:56:25 -08:00
source-map-test build: update npm dependencies (#19328) 2017-09-22 13:20:52 -07:00
symbol-extractor ci: fix symbol test to handle duplicate symbols (#28459) 2019-01-31 12:26:16 -05:00
testing fix(core): Remove static dependency from @angular/core to @angular/compiler (#26734) 2018-10-31 14:15:06 -04:00
ts-api-guardian feat: add support for typescript 3.2 (#27536) 2018-12-18 13:20:01 -08:00
tslint build: remove unused rollup.config.js files (#28646) 2019-02-14 19:28:08 +00:00
validate-commit-message ci: remove validate-commit-message tests from travis (#27386) 2018-12-05 20:55:32 -08:00
yarn build: upgrade yarn to 1.3.2 (#21406) 2018-01-10 12:32:26 -08:00
BUILD.bazel build: update to Bazel 0.20 (#27394) 2018-12-07 14:29:03 -08:00
bazel_stamp_vars.js build: use cross platform workspace_status_command (#27431) 2019-01-09 10:47:13 -08:00
check-environment.js build: update to Node 10 (#25822) 2018-09-06 14:58:30 -07:00
defaults.bzl build(bazel): specify tsconfig-test dependency (#28696) 2019-02-16 20:57:34 -08:00
jasmine-seed-generator.js test: run unit tests in random order (#19904) 2018-07-06 13:48:02 -07:00
jsconfig.json
ng_setup_workspace.bzl build: update to rules_typescript 0.23.2 and rules_nodejs 0.16.8 (#28532) 2019-02-05 16:55:43 -05:00
postinstall-patches.js build: disable postinstall-patch.js log output (#27619) 2018-12-13 11:01:15 -08:00
tsconfig-test.json build(bazel): use fine-grained npm deps (#26111) (#26488) 2018-10-19 20:59:29 -07:00
tsconfig.json build: ts-api-guardian tsconfig warning with bazel (#27583) 2018-12-13 11:01:48 -08:00
types.d.ts build(bazel): use bazel managed node_modules for downstream angular from source build support (#24663) 2018-07-26 17:02:21 -07:00
utils.inc