_Reference to a local (non-exported) symbol 'symbol name'. Consider exporting the symbol._
@@ -855,8 +1060,12 @@ _Reference to a local (non-exported) symbol 'symbol name'. Consider exporting th
The compiler encountered a referenced to a locally defined symbol that either wasn't exported or wasn't initialized.
+编译器遇到了局部定义的未导出或未初始化的符号。
+
Here's a `provider` example of the problem.
+下面就是存在该问题的 `provider` 范例。
+
```
// ERROR
@@ -875,8 +1084,12 @@ export class MyComponent {}
The compiler generates the component factory, which includes the `useValue` provider code, in a separate module. _That_ factory module can't reach back to _this_ source module to access the local (non-exported) `foo` variable.
+编译器会在单独的模块中生成这个 `userValue` 提供商的代码。*那个*工厂模块不能访问*这个*源码模块,无法访问这个(未导出的)`foo` 变量。
+
You could fix the problem by initializing `foo`.
+你可以通过初始化 `foo` 来修正这个错误。
+
```
let foo = 42; // initialized
@@ -885,6 +1098,8 @@ let foo = 42; // initialized
The compiler will [fold](#folding) the expression into the provider as if you had written this.
+编译器将会把这个表达式[折叠](#folding)进 `providers` 中,就像你以前的写法一样。
+
```
providers: [
@@ -895,6 +1110,8 @@ The compiler will [fold](#folding) the expression into the provider as if you ha
Alternatively, you can fix it by exporting `foo` with the expectation that `foo` will be assigned at runtime when you actually know its value.
+另外,你也可以通过导出 `foo` 来解决它,这样 `foo` 将会在运行期间你真正知道它的值的时候被赋值。
+
```
// CORRECTED
@@ -913,10 +1130,14 @@ export class MyComponent {}
Adding `export` often works for variables referenced in metadata such as `providers` and `animations` because the compiler can generate _references_ to the exported variables in these expressions. It doesn't need the _values_ of those variables.
+添加 `export` 的方式通常用于需要在元数据中引用变量时,如 `providers` 和 `animations`,这样编译器就可以在这些表达式中生成对已导出变量的引用了。它不需要知道这些变量的*值*。
+
Adding `export` doesn't work when the compiler needs the _actual value_
in order to generate code.
For example, it doesn't work for the `template` property.
+当编译器需要知道*真正的值*已生成代码时,添加 `export` 的方式就是无效的。比如这里的 `template` 属性。
+
```
// ERROR
@@ -934,12 +1155,18 @@ The compiler needs the value of the `template` property _right now_ to generate
The variable reference alone is insufficient.
Prefixing the declaration with `export` merely produces a new error, "[`Only initialized variables and constants can be referenced`](#only-initialized-variables)".
+编译器*现在就*需要 `template` 属性的值来生成组件工厂。
+仅仅有对该变量的引用是不够的。
+给这个声明加上 `export` 前缀只会生成一个新的错误 "[`Only initialized variables and constants can be referenced`【只能引用初始化过的变量和常量】](#only-initialized-variables)"。
+
{@a only-initialized-variables}
Only initialized variables and constants
+
只允许使用初始化过的变量和常量
+
_Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler._
@@ -949,9 +1176,13 @@ _Only initialized variables and constants can be referenced because the value of
The compiler found a reference to an exported variable or static field that wasn't initialized.
It needs the value of that variable to generate code.
+编译器发现某个到已导出的变量或静态字段的引用是没有初始化过的。而它需要根据那个变量的值来生成代码。
+
The following example tries to set the component's `template` property to the value of
the exported `someTemplate` variable which is declared but _unassigned_.
+下面的例子试图把组件的 ` template` 属性设置为已导出的 `someTemplate` 变量的值,而这个值虽然声明过,却没有初始化过。
+
```
// ERROR
@@ -967,6 +1198,8 @@ export class MyComponent {}
You'd also get this error if you imported `someTemplate` from some other module and neglected to initialize it there.
+如果你从其它模块中导入了 `someTemplate`,但那个模块中忘了初始化它,就会看到这个错误。
+
```
// ERROR - not initialized there either
@@ -985,8 +1218,13 @@ It must statically derive the value of the `someTemplate` variable from the sour
so that it can generate the component factory, which includes
instructions for building the element based on the template.
+编译器不能等到运行时才得到该模板的信息。
+它必须从源码中静态获得这个 `someTemplate` 变量的值,以便生成组件工厂,组件工厂中需要包含根据这个模板来生成元素的代码。
+
To correct this error, provide the initial value of the variable in an initializer clause _on the same line_.
+要纠正这个错误,请在*同一行*的初始化子句中初始化这个变量的值。
+
```
// CORRECTED
@@ -1004,6 +1242,8 @@ export class MyComponent {}
Reference to a non-exported class
+
引用了未导出的类
+
_Reference to a non-exported class
. Consider exporting the class._
@@ -1012,9 +1252,13 @@ _Reference to a non-exported class . Consider exporting the class._
Metadata referenced a class that wasn't exported.
+元数据引用了一个未导出的类。
+
For example, you may have defined a class and used it as an injection token in a providers array
but neglected to export that class.
+比如,你可能定义了一个类并在某个 `providers` 数组中把它用作了依赖注入令牌,但是忘了导出这个类。
+
```
// ERROR
@@ -1032,6 +1276,9 @@ Angular generates a class factory in a separate module and that
factory [can only access exported classes](#exported-symbols).
To correct this error, export the referenced class.
+Angular 会在一个单独的模块中生成类工厂,而那个工厂[只能访问已导出的类](#exported-symbols)。
+要纠正这个问题,就要导出所引用的类。
+
```
// CORRECTED
@@ -1049,10 +1296,16 @@ export abstract class MyStrategy { }
Reference to a non-exported function
+引用了未导出的函数
+
Metadata referenced a function that wasn't exported.
+元数据中引用了未导出的函数。
+
For example, you may have set a providers `useFactory` property to a locally defined function that you neglected to export.
+比如,你可能已经把某个服务提供商的 `useFactory` 属性设置成了一个局部定义但忘了导出的函数。
+
```
// ERROR
@@ -1070,6 +1323,9 @@ Angular generates a class factory in a separate module and that
factory [can only access exported functions](#exported-symbols).
To correct this error, export the function.
+Angular 会在一个单独的模块中生成类工厂,那个工厂[只能访问已导出的函数](#exported-symbols)。
+要纠正这个错误,请导出该函数。
+
```
// CORRECTED
@@ -1089,6 +1345,8 @@ export function myStrategy() { ... }
Function calls are not supported
+不支持函数调用
+
_Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function._
@@ -1098,6 +1356,9 @@ _Function calls are not supported. Consider replacing the function or lambda wit
The compiler does not currently support [function expressions or lambda functions](#function-expression).
For example, you cannot set a provider's `useFactory` to an anonymous function or arrow function like this.
+编译器目前不支持[函数表达式或 Lambda 表达式](#function-expression)。
+比如,你不能把某个服务提供商的 `useFactory` 设置成如下匿名函数或函数表达式。
+
```
// ERROR
@@ -1112,6 +1373,8 @@ For example, you cannot set a provider's `useFactory` to an anonymous function o
You also get this error if you call a function or method in a provider's `useValue`.
+如果你在某个提供商的 `useValue` 中调用函数或方法,也会导致这个错误。
+
```
// ERROR
@@ -1127,6 +1390,8 @@ import { calculateValue } from './utilities';
To correct this error, export a function from the module and refer to the function in a `useFactory` provider instead.
+要改正这个问题,就要从模块中导出这个函数,并改成在服务提供商的 `useFactory` 中引用该函数。
+
// CORRECTED
@@ -1153,6 +1418,8 @@ export function someValueFactory() {
Destructured variable or constant not supported
+不支持解构变量或常量
+
_Referencing an exported destructured variable or constant is not supported by the template compiler. Consider simplifying this to avoid destructuring._
@@ -1161,8 +1428,12 @@ _Referencing an exported destructured variable or constant is not supported by t
The compiler does not support references to variables assigned by [destructuring](https://www.typescriptlang.org/docs/handbook/variable-declarations.html#destructuring).
+编译器不支持引用通过[解构](https://www.typescriptlang.org/docs/handbook/variable-declarations.html#destructuring)赋值的方式得到的变量。
+
For example, you cannot write something like this:
+比如,你不能这么写:
+
// ERROR
@@ -1181,6 +1452,8 @@ const {foo, bar} = configuration;
To correct this error, refer to non-destructured values.
+要纠正这个错误,就要引用非解构方式的变量。
+
// CORRECTED
@@ -1198,14 +1471,23 @@ import { configuration } from './configuration';
Could not resolve type
+不能解析类型
+
The compiler encountered a type and can't determine which module exports that type.
+编译器遇到了某个类型,但是不知道它是由哪个模块导出的。
+
This can happen if you refer to an ambient type.
For example, the `Window` type is an ambiant type declared in the global `.d.ts` file.
+这通常会发生在你引用环境类型时。
+比如,`Window` 类型就是在全局 `.d.ts` 文件中声明的环境类型。
+
You'll get an error if you reference it in the component constructor,
which the compiler must statically analyze.
+如果你在组件的构造函数中引用它就会导致一个错误,因为编译器必须对构造函数进行静态分析。
+
```
// ERROR
@@ -1219,23 +1501,42 @@ export class MyComponent {
TypeScript understands ambiant types so you don't import them.
The Angular compiler does not understand a type that you neglect to export or import.
+TypeScript 能理解这些环境类型,所以你不用导入它们。
+但 Angular 编译器不理解你没有导入或导出过的类型。
+
In this case, the compiler doesn't understand how to inject something with the `Window` token.
+这种情况下,编译器就无法理解如何使用这个 `Window` 令牌来进行注入。
+
Do not refer to ambient types in metadata expressions.
+不要在元数据表达式中引用环境类型。
+
If you must inject an instance of an ambiant type,
you can finesse the problem in four steps:
+如果你必须注入某个环境类型的实例,可以用以下四步来巧妙解决这个问题:
+
1. Create an injection token for an instance of the ambiant type.
+ 为环境类型的实例创建一个注入令牌。
+
1. Create a factory function that returns that instance.
+ 创建一个返回该实例的工厂函数。
+
1. Add a `useFactory` provider with that factory function.
+ 使用该工厂函数添加一个 `useFactory` 提供商。
+
1. Use `@Inject` to inject the instance.
+ 使用 `@Inject` 来注入这个实例。
+
Here's an illustrative example.
+下面的例子说明了这一点。
+
// CORRECTED
@@ -1259,8 +1560,12 @@ export class MyComponent {
The `Window` type in the constructor is no longer a problem for the compiler because it
uses the `@Inject(WINDOW)` to generate the injection code.
+对于编译器来说,构造函数中出现 `Window` 类型已不再是个问题,因为它现在使用 `@Inject(WINDOW)` 来生成注入代码。
+
Angular does something similar with the `DOCUMENT` token so you can inject the browser's `document` object (or an abstraction of it, depending upon the platform in which the application runs).
+Angular 也用 `DOCUMENT` 令牌做了类似的事情,所以你也可以注入浏览器的 `document` 对象(或它的一个抽象层,取决于该应用运行在哪个平台)。
+
import { Inject } from '@angular/core';
@@ -1277,9 +1582,13 @@ export class MyComponent {
Name expected
+期待是名字
+
The compiler expected a name in an expression it was evaluating.
This can happen if you use a number as a property name as in the following example.
+编译器期待它正在求值的表达式中是一个名字。
+
```
// ERROR
@@ -1300,11 +1609,17 @@ provider: [{ provide: Foo, useValue: { '0': 'test' } }]
Unsupported enum member name
+不支持的枚举成员名
+
Angular couldn't determine the value of the [enum member](https://www.typescriptlang.org/docs/handbook/enums.html)
that you referenced in metadata.
+Angular 不能确定你在元数据中引用的[枚举成员](https://www.typescriptlang.org/docs/handbook/enums.html)的值。
+
The compiler can understand simple enum values but not complex values such as those derived from computed properties.
+编译器可以理解简单的枚举值,但不能理解复杂的,比如从那些计算属性中派生出来的。
+
// ERROR
@@ -1326,12 +1641,16 @@ enum Colors {
Avoid referring to enums with complicated initializers or computed properties.
+避免引用那些使用了复杂初始化对象或计算属性的枚举。
+
{@a tagged-template-expressions-not-supported}
Tagged template expressions are not supported
+不支持带标签函数的模板表达式
+
_Tagged template expressions are not supported in metadata._
@@ -1340,6 +1659,8 @@ _Tagged template expressions are not supported in metadata._
The compiler encountered a JavaScript ES2015 [tagged template expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) such as,
+当编译器遇到这样的[带标签函数的模板表达式](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) 时:
+
```
// ERROR
@@ -1354,16 +1675,26 @@ const raw = String.raw`A tagged template ${expression} string`;
[`String.raw()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
is a _tag function_ native to JavaScript ES2015.
+[`String.raw()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) 是一个 ES2015 原生的*标签函数*。
+
The AOT compiler does not support tagged template expressions; avoid them in metadata expressions.
+AOT 编译器不支持带标签函数的模板表达式,避免在元数据表达式中使用它们。
+
Symbol reference expected
+期待是符号引用
+
The compiler expected a reference to a symbol at the location specified in the error message.
+编译器期待在错误信息指出的位置是一个符号引用。
+
This error can occur if you use an expression in the `extends` clause of a class.
+当你在类的 `extends` 子句中使用表达式时就会出现这个错误。
+