5 lines
9.4 KiB
JSON
5 lines
9.4 KiB
JSON
|
{
|
||
|
"id": "guide/migration-dynamic-flag",
|
||
|
"title": "Dynamic queries flag migration",
|
||
|
"contents": "\n\n\n<div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/aio/content/guide/migration-dynamic-flag.md?message=docs%3A%20describe%20your%20change...\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n</div>\n\n\n<div class=\"content\">\n <h1 id=\"dynamic-queries-flag-migration\">Dynamic queries flag migration<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/migration-dynamic-flag#dynamic-queries-flag-migration\"><i class=\"material-icons\">link</i></a></h1>\n<h2 id=\"what-does-this-migration-do\">What does this migration do?<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/migration-dynamic-flag#what-does-this-migration-do\"><i class=\"material-icons\">link</i></a></h2>\n<p>In Angular version 8, a schematic added <code><a href=\"api/upgrade/static\" class=\"code-anchor\">static</a></code> flags to all <code>@<a href=\"api/core/ViewChild\" class=\"code-anchor\">ViewChild</a>()</code> and <code>@<a href=\"api/core/ContentChild\" class=\"code-anchor\">ContentChild</a>()</code> queries.\nThis was the first step towards changing the default behavior.\nWith version 9, the default value changes to <code><a href=\"api/upgrade/static\" class=\"code-anchor\">static</a>: false</code> and the flag becomes optional.</p>\n<p>This schematic scans classes in the compilation and for each class, checks if the members have a <code>@<a href=\"api/core/ViewChild\" class=\"code-anchor\">ViewChild</a>()</code> or <code>@<a href=\"api/core/ContentChild\" class=\"code-anchor\">ContentChild</a>()</code> query with the <code><a href=\"api/upgrade/static\" class=\"code-anchor\">static</a></code> flag set to <code>false</code>.\nIf so, the schematic removes the flag, as it now matches the default.</p>\n<p><strong>Before:</strong></p>\n<code-example language=\"ts\">\n@<a href=\"api/core/ViewChild\" class=\"code-anchor\">ViewChild</a>('foo', {<a href=\"api/upgrade/static\" class=\"code-anchor\">static</a>: false}) foo: <a href=\"api/core/ElementRef\" class=\"code-anchor\">ElementRef</a>;\n\n@<a href=\"api/core/ViewChild\" class=\"code-anchor\">ViewChild</a>('bar', {<a href=\"api/upgrade/static\" class=\"code-anchor\">static</a>: true}) bar: <a href=\"api/core/ElementRef\" class=\"code-anchor\">ElementRef</a>;\n</code-example>\n<p><strong>After:</strong></p>\n<code-example language=\"ts\">\n@<a href=\"api/core/ViewChild\" class=\"code-anchor\">ViewChild</a>('foo') foo: <a href=\"api/core/ElementRef\" class=\"code-anchor\">ElementRef</a>;\n\n// this <a href=\"api/animations/query\" class=\"code-anchor\">query</a> doesn't change because the <a href=\"api/upgrade/static\" class=\"code-anchor\">static</a> value is true\n@<a href=\"api/core/ViewChild\" class=\"code-anchor\">ViewChild</a>('bar', {<a href=\"api/upgrade/static\" class=\"code-anchor\">static</a>: true}) bar: <a href=\"api/core/ElementRef\" class=\"code-anchor\">ElementRef</a>;\n</code-example>\n<p>Note that the flag is not supported in <code>@<a href=\"api/core/ViewChildren\" class=\"code-anchor\">ViewChildren</a>()</code> or <code>@<a href=\"api/core/ContentChildren\" class=\"code-anchor\">ContentChildren</a>()</code> queries, so the schematic will not check these properties.</p>\n<h2 id=\"why-is-this-migration-necessary\">Why is this migration necessary?<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/migration-dynamic-flag#why-is-this-migration-necessary\"><i class=\"material-icons\">link</i></a></h2>\n<p>This schematic performs a code cleanup to remove <code><a href=\"api/upgrade/static\" class=\"code-anchor\">static</a></code> flags that match the default, as they are no longer necessary.\nFunctionally, the code change should be a noop.</p>\n<p>Before version 9, Angular figured out the static or dynamic nature of a query automatically, based on how the template was written.\nLooking at templates in this way, however, caused buggy and s
|
||
|
}
|