diff --git a/aio/content/errors/NG0100.md b/aio/content/errors/NG0100.md new file mode 100644 index 0000000000..78ce635cf2 --- /dev/null +++ b/aio/content/errors/NG0100.md @@ -0,0 +1,20 @@ +@name Expression Changed After Checked +@category runtime +@videoUrl https://www.youtube.com/embed/O47uUnJjbJc +@shortDescription Expression has changed after it was checked + +@description +Angular throws an `ExpressionChangedAfterItHasBeenCheckedError` when an expression value has been changed after change detection has completed. Angular only throws this error in development mode. + +In dev mode, Angular performs an additional check after each change detection run, to ensure the bindings haven’t changed. This catches errors where the view is left in an inconsistent state. This can occur, for example, if a method or getter returns a different value each time it is called, or if a child component changes values on its parent. If either of these occur, this is a sign that change detection is not stabilized. Angular throws the error to ensure data is always reflected correctly in the view, which prevents erratic UI behavior or a possible infinite loop. + +This error commonly occurs when you’ve added template expressions or begun to implement lifecycle hooks like `ngAfterViewInit` or `ngOnChanges`. It is also common when dealing with loading status and asynchronous operations, or a child component changes its parent bindings. + +@debugging +The [source maps](https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map) generated by the CLI are very useful when debugging. Navigate up the call stack until you find a template expression where the value displayed in the error has changed. + +Ensure that there are no changes to the bindings in the template after change detection is run. This often means refactoring to use the correct [component lifecycle hook](guide/lifecycle-hooks) for your use case. If the issue exists within `ngAfterViewInit`, the recommended solution is to use a constructor or `ngOnInit` to set initial values, or use `ngAfterContentInit` for other value bindings. + +If you are binding to methods in the view, ensure that the invocation does not update any of the other bindings in the template. + +Read more about which solution is right for you in ['Everything you need to know about the "ExpressionChangedAfterItHasBeenCheckedError" error'](https://indepth.dev/everything-you-need-to-know-about-the-expressionchangedafterithasbeencheckederror-error/) and why this is useful at ['Angular Debugging "Expression has changed after it was checked": Simple Explanation (and Fix)'](https://blog.angular-university.io/angular-debugging/). diff --git a/aio/content/errors/NG0200.md b/aio/content/errors/NG0200.md new file mode 100644 index 0000000000..4965761fb3 --- /dev/null +++ b/aio/content/errors/NG0200.md @@ -0,0 +1,12 @@ +@name Circular Dependency in DI +@category runtime +@videoUrl https://www.youtube.com/embed/CpLOm4o_FzM +@shortDescription Circular dependency in DI detected while instantiating a provider + +@description +A cyclic dependency exists when a [dependency of a service](guide/hierarchical-dependency-injection) directly or indirectly depends on the service itself. For example, if `UserService` depends on `EmployeeService`, which also depends on `UserService`. Angular will have to instantiate `EmployeeService` to create `UserService`, which depends on `UserService`, itself. + +@debugging +Use the call stack to determine where the cyclical dependency exists. You will be able to see if any child dependencies rely on the original file by [mapping out](guide/dependency-injection-in-action) the component, module, or service’s dependencies and identify the loop causing the problem. + +Break this loop (or circle) of dependency to resolve this error. This most commonly means removing or refactoring the dependencies to not be reliant on one another. diff --git a/aio/content/errors/NG0201.md b/aio/content/errors/NG0201.md new file mode 100644 index 0000000000..c5fd8069f1 --- /dev/null +++ b/aio/content/errors/NG0201.md @@ -0,0 +1,20 @@ +@name No Provider Found +@category runtime +@videoUrl https://www.youtube.com/embed/lAlOryf1-WU +@shortDescription No provider for {token} found! + +@description +You see this error when you try to inject a service but have not declared a corresponding provider. A provider is a mapping that supplies a value that you can inject into the constructor of a class in your application. + +Read more on providers in our [Dependency Injection guide](guide/dependency-injection). + +@debugging +Work backwards from the object where the error states that a [provider](guide/architecture-services) is missing: `No provider for ${this}!`. This is commonly thrown in [services](tutorial/toh-pt4), which require non-existing providers. + +To fix the error ensure that your service is registered in the list of providers of an `NgModule` or has the `@Injectable` decorator with a `providedIn` property at top. + +The most common solution is to add a provider in `@Injectable` using `providedIn`: + +```typescript +@Injectable({ providedIn: 'app' }) +``` diff --git a/aio/content/errors/NG0300.md b/aio/content/errors/NG0300.md new file mode 100644 index 0000000000..3d91a5c783 --- /dev/null +++ b/aio/content/errors/NG0300.md @@ -0,0 +1,21 @@ +@name Selector Collision +@category runtime +@videoUrl https://www.youtube.com/embed/z_3Z5mOm59I +@shortDescription Multiple components match with the same tagname + +@description +Two or more components use the same [element selector](guide/component-overview#specifying-a-components-css-selector). Because there can only be a single component associated with an element, selectors must be unique strings to prevent ambiguity for Angular. + +@debugging +Use the element name from the error message to search for places where you’re using the same [selector declaration](guide/architecture-components) in your codebase: + +```typescript +@Component({ + selector: 'YOUR_STRING', + ... +}) +``` + +Ensure that each component has a unique CSS selector. This will guarantee that Angular renders the component you expect. + +If you’re having trouble finding multiple components with this selector tag name, check for components from imported component libraries, such as Angular Material. Make sure you're following the [best practices](guide/styleguide#component-selectors) for your selectors to prevent collisions. diff --git a/aio/content/errors/NG0301.md b/aio/content/errors/NG0301.md new file mode 100644 index 0000000000..67135f6c1c --- /dev/null +++ b/aio/content/errors/NG0301.md @@ -0,0 +1,32 @@ +@name Export Not Found +@category runtime +@videoUrl https://www.youtube.com/embed/fUSAg4kp2WQ +@shortDescription Export not found! + +@description +Angular can’t find a directive with `{{ PLACEHOLDER }}` export name. The export name is specified in the `exportAs` property of the directive decorator. This is common when using FormsModule or Material modules in templates, and you’ve forgotten to [import the corresponding modules](guide/sharing-ngmodules). + +
+ +This is the runtime equivalent of a common compiler error [NG8003: No directive found with export](errors/NG8003). + +
+ +@debugging +Use the export name to trace the templates or modules using this export. + +Ensure that all dependencies are [properly imported and declared in your NgModules](guide/sharing-ngmodules). For example, if the export not found is `ngForm`, we need to import `FormsModule` and declare it in the list of imports in `*.module.ts` to resolve the error. + +```typescript +import { FormsModule } from '@angular/forms'; + +@NgModule({ + ... + imports: [ + FormsModule, + … +``` + +If you recently added an import, you may need to restart your server to see these changes. + + diff --git a/aio/content/errors/NG0302.md b/aio/content/errors/NG0302.md new file mode 100644 index 0000000000..597dbfc9bf --- /dev/null +++ b/aio/content/errors/NG0302.md @@ -0,0 +1,18 @@ +@name Pipe Not Found +@category runtime +@videoUrl https://www.youtube.com/embed/maI2u6Sxk9M +@shortDescription Pipe not found! + +@description +Angular can't find a pipe with this name. +The pipe referenced in the template has not been named or declared properly. +A [pipe](guide/pipes) must be either declared or imported in the `NgModule` where it is used, and the name used in a template must match the name defined in the pipe decorator. + +@debugging +Use the pipe name to trace the templates or modules where this pipe is declared and used. + +To resolve this error, ensure that: +- A local custom pipe is uniquely named in the pipe's decorator, and declared in the `NgModule`, or +- A pipe from another `NgModule` is added to the imports of the `NgModule` where it is used. + +If you recently added an import or declaration, you may need to restart your server to see these changes. diff --git a/aio/content/errors/NG1001.md b/aio/content/errors/NG1001.md new file mode 100644 index 0000000000..59d25a9fbf --- /dev/null +++ b/aio/content/errors/NG1001.md @@ -0,0 +1,29 @@ +@name Argument Not Literal +@category compiler +@shortDescription Decorator argument is not an object literal + +@description +To make the metadata extraction in the Angular compiler faster, the decorators `@NgModule`, `@Pipe`, `@Component`, `@Directive`, and `@Injectable` accept only object literals as arguments. + +This is an [intentional change in Ivy](https://github.com/angular/angular/issues/30840#issuecomment-498869540), which enforces stricter argument requirements for decorators than View Engine. Ivy requires this approach because it compiles decorators by moving the expressions into other locations in the class output. + +@debugging +Move all declarations: + +```typescript +const moduleDefinition = {...} + +@NgModule(moduleDefinition) +export class AppModule { + constructor() {} +} +``` + +into the decorator: + +```typescript +@NgModule({...}) +export class AppModule { + constructor() {} +} +``` diff --git a/aio/content/errors/NG2003.md b/aio/content/errors/NG2003.md new file mode 100644 index 0000000000..b8cfe87669 --- /dev/null +++ b/aio/content/errors/NG2003.md @@ -0,0 +1,11 @@ +@name Missing Token +@category compiler +@shortDescription No suitable injection token for parameter + +@description +There is no injection token for a constructor parameter at compile time. [InjectionTokens](api/core/InjectionToken) are tokens that can be used in a Dependency Injection Provider. + +@debugging +Look at the parameter that throws the error and all uses of the class. This error is commonly thrown when a constructor defines parameters with primitive types like `string`, `number`, `boolean`, and `Object`. + +Use the [@Injectable](api/core/Injectable) method or [@Inject](api/core/Inject) decorator from `@angular/core` to ensure that the type you are injecting is reified (has a runtime representation). Make sure to add a provider to this decorator so that you do not throw [NG0201: No Provider Found](errors/NG0201). diff --git a/aio/content/errors/NG3003.md b/aio/content/errors/NG3003.md new file mode 100644 index 0000000000..6016d823d6 --- /dev/null +++ b/aio/content/errors/NG3003.md @@ -0,0 +1,55 @@ +@name Import Cycle Detected +@category compiler +@shortDescription Import cycles would need to be created to compile this component + +@description + +A component, directive or pipe that is referenced by this component would require the compiler +to add an import that would lead to a cycle of imports. For example, consider a scenario where +a `ParentComponent` references a `ChildComponent` in its template: + + + + + +There is already an import from `child.component.ts` to `parent.component.ts` since the `ChildComponent` +references the `ParentComponent` in its constructor. + +But note that the parent component's template contains ``. The generated code for this +template must therefore contain a reference to the `ChildComponent` class. In order to make this reference +the compiler would have to add an import from `parent.component.ts` to `child.component.ts`, which would +cause an import cycle: + +``` +parent.component.ts -> child.component.ts -> parent.component.ts +``` + +### Remote Scoping + +To avoid adding imports that create cycles, additional code is added to the `NgModule` class where +the component is declared that wires up the dependencies. This is known as "remote scoping". + + +### Libraries + +Unfortunately, "remote scoping" code is side-effectful, which prevents tree shaking, and cannot +be used in libraries. So when building libraries using the `"compilationMode": "partial"` setting, +any component that would require a cyclic import will cause this `NG3003` compiler error to be raised. + + +@debugging + +The cycle that would be generated is shown as part of the error message. For example: + + +The component ChildComponent is used in the template but importing it would create a cycle: +/parent.component.ts -> /child.component.ts -> /parent.component.ts + + +Use this to identify how the referenced component, pipe or directive has a dependency back to the +component being compiled. Here are some ideas for fixing the problem: + +* Try to re-arrange your dependencies to avoid the cycle. For example using an intermediate interface +that is stored in an independent file that can be imported to both dependent files without +causing an import cycle. +* Move the classes that reference each other into the same file, to avoid any imports between them. diff --git a/aio/content/errors/NG8001.md b/aio/content/errors/NG8001.md new file mode 100644 index 0000000000..19faf07087 --- /dev/null +++ b/aio/content/errors/NG8001.md @@ -0,0 +1,21 @@ +@name Invalid Element +@category compiler +@shortDescription Unknown HTML element or component + +@description +One or more elements cannot be resolved during compilation because the element is not defined by the HTML spec, or there is no component or directive with such element selector. + +
+ +This is the compiler equivalent of a common runtime error `NG0304: '${tagName}' is not a known element: …`. + +
+ +@debugging +Use the element name in the error to find the file(s) where the element is being used. + +Check that the name and selector are correct. If the component is from a different module or import, check that the component is exported from its origin module and imported into the correct `*.modules.ts` file, and declared in the imports list. + +When using custom elements or web components, ensure that you add [`CUSTOM_ELEMENTS_SCHEMA`](api/core/CUSTOM_ELEMENTS_SCHEMA) to the app module. + +If this does not resolve the error, check the imported libraries for any recent changes to the exports and properties you are using, and restart your server. diff --git a/aio/content/errors/NG8002.md b/aio/content/errors/NG8002.md new file mode 100644 index 0000000000..a0fd6916d5 --- /dev/null +++ b/aio/content/errors/NG8002.md @@ -0,0 +1,16 @@ +@name Invalid Attribute +@category compiler +@videoUrl https://www.youtube.com/embed/wfLkB3RsSJM +@shortDescription Unknown attribute or input + +@description +An attribute or property cannot be resolved during compilation. + +This error arises when attempting to bind to a property that does not exist. Any property binding must correspond to either: +* A native property on the HTML element, or +* An `@Input()` property of a component or directive applied to the element. + +The runtime error for this is `NG0304: '${tagName}' is not a known element: …’`. + +@debugging +Look at documentation for the specific [binding syntax](guide/binding-syntax) used. This is usually a typo or incorrect import. There may also be a missing direction with property selector ‘name’ or missing input. diff --git a/aio/content/errors/NG8003.md b/aio/content/errors/NG8003.md new file mode 100644 index 0000000000..f97a30d72f --- /dev/null +++ b/aio/content/errors/NG8003.md @@ -0,0 +1,31 @@ +@name Missing Reference Target +@category compiler +@videoUrl https://www.youtube.com/embed/fUSAg4kp2WQ +@shortDescription No directive found with export + +@description +Angular can’t find a directive with `{{ PLACEHOLDER }}` export name. This is common with a missing import or a missing [`exportAs`](api/core/Directive#exportAs) on a directive. + + +
+ +This is the compiler equivalent of a common runtime error [NG0301: Export Not Found](errors/NG0301). + +
+ +@debugging +Use the string name of the export not found to trace the templates or modules using this export. + +Ensure that all dependencies are properly imported and declared in our Modules. For example, if the export not found is `ngForm`, we will need to import `FormsModule` and declare it in our list of imports in `*.module.ts` to resolve the missing export error. + +```typescript +import { FormsModule } from '@angular/forms'; + +@NgModule({ + ... + imports: [ + FormsModule, + … +``` + +If you recently added an import, you will need to restart your server to see these changes. diff --git a/aio/content/errors/index.md b/aio/content/errors/index.md new file mode 100644 index 0000000000..ecff113c4a --- /dev/null +++ b/aio/content/errors/index.md @@ -0,0 +1 @@ +# Errors List \ No newline at end of file