angular-cn/aio/dist/generated/docs/guide/aot-metadata-errors.json

5 lines
23 KiB
JSON
Raw Normal View History

{
"id": "guide/aot-metadata-errors",
"title": "AOT metadata errors",
"contents": "\n\n\n<div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/aio/content/guide/aot-metadata-errors.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=\"aot-metadata-errors\">AOT metadata errors<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/aot-metadata-errors#aot-metadata-errors\"><i class=\"material-icons\">link</i></a></h1>\n<p>The following are metadata errors you may encounter, with explanations and suggested corrections.</p>\n<p><a href=\"guide/aot-metadata-errors#expression-form-not-supported\">Expression form not supported</a><br>\n<a href=\"guide/aot-metadata-errors#reference-to-a-local-symbol\">Reference to a local (non-exported) symbol</a><br>\n<a href=\"guide/aot-metadata-errors#only-initialized-variables\">Only initialized variables and constants</a><br>\n<a href=\"guide/aot-metadata-errors#reference-to-a-non-exported-class\">Reference to a non-exported class</a><br>\n<a href=\"guide/aot-metadata-errors#reference-to-a-non-exported-function\">Reference to a non-exported function</a><br>\n<a href=\"guide/aot-metadata-errors#function-calls-not-supported\">Function calls are not supported</a><br>\n<a href=\"guide/aot-metadata-errors#destructured-variable-not-supported\">Destructured variable or constant not supported</a><br>\n<a href=\"guide/aot-metadata-errors#could-not-resolve-type\">Could not resolve type</a><br>\n<a href=\"guide/aot-metadata-errors#name-expected\">Name expected</a><br>\n<a href=\"guide/aot-metadata-errors#unsupported-enum-member-name\">Unsupported enum member name</a><br>\n<a href=\"guide/aot-metadata-errors#tagged-template-expressions-not-supported\">Tagged template expressions are not supported</a><br>\n<a href=\"guide/aot-metadata-errors#symbol-reference-expected\">Symbol reference expected</a><br></p>\n<a id=\"expression-form-not-supported\"></a>\n<h2 id=\"expression-form-not-supported\">Expression form not supported<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/aot-metadata-errors#expression-form-not-supported\"><i class=\"material-icons\">link</i></a></h2>\n<div class=\"alert is-helpful\">\n<p><em>The compiler encountered an expression it didn't understand while evaluating Angular metadata.</em></p>\n</div>\n<p>Language features outside of the compiler's <a href=\"guide/aot-compiler#expression-syntax\">restricted expression syntax</a>\ncan produce this error, as seen in the following example:</p>\n<code-example language=\"ts\">\n// ERROR\nexport class Fooish { ... }\n...\nconst prop = typeof Fooish; // typeof is not valid in metadata\n ...\n // bracket notation is not valid in metadata\n { provide: 'token', useValue: { [prop]: 'value' } };\n ...\n</code-example>\n<p>You can use <code>typeof</code> and bracket notation in normal application code.\nYou just can't use those features within expressions that define Angular metadata.</p>\n<p>Avoid this error by sticking to the compiler's <a href=\"guide/aot-compiler#expression-syntax\">restricted expression syntax</a>\nwhen writing Angular metadata\nand be wary of new or unusual TypeScript features.</p>\n<a id=\"reference-to-a-local-symbol\"></a>\n<h2 id=\"reference-to-a-local-non-exported-symbol\">Reference to a local (non-exported) symbol<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/aot-metadata-errors#reference-to-a-local-non-exported-symbol\"><i class=\"material-icons\">link</i></a></h2>\n<div class=\"alert is-helpful\">\n<p><em>Reference to a local (non-exported) symbol 'symbol name'. Consider exporting the symbol.</em></p>\n</div>\n<p>The compiler encountered a referenced to a locally defined symbol that either wasn't exported or wasn't initialized.</p>\n<p>Here's a <code>provider</code> example of the problem.</p>\n<code-example language=\"ts\">\n// ERROR\nlet foo: number; // ne
}