Decorators should have parentheses
() after an annotation. Some examples include:
This exception means that Angular is confused about one or more of the parameters for
YourClass's constructor. In order to do dependency injection Angular needs to know the type of the parameter to inject. You let Angular know this by specifying the class of the parameter. Make sure:
- You are importing the parameter's class.
- You have properly annotated the parameter or specified its type.
Sometimes circular references within your code can cause this error. Circular references mean that two objects depend on each other, and so there is no way to declare both of them before each other. To get around this, we can use the
forwardRef function built in to Angular.
This means Angular knows the type of parameter it is supposed to inject, but it doesn't know how to inject it.
If the parameter is a service, make sure you have added the specified class to the list of providers available to your app:
If the parameter is another component or directive (for example, a parent component), adding it to your list of providers will make the error go away, but this will have the same effect as the Multiple instances of a provider above. You'll be creating a new instance of the component class, and you won't get a reference to the component instance you want. Instead, make sure that the directive or component you expect to be injected is available to your component (e.g. that it is actually a parent if you are expecting it to be a parent). This is probably easiest understood with an example:
Here's a diagram illustrating what injectors are available:
To expand on the previous example, you can use the Angular
@Optional annotation if you don't always expect a component/directive reference:
This happens when you try and bind a property on an element that doesn't have that property. If the element is a component or has one or more directives on it, neither the component nor the directives have that property either.
This error is a more specific version of the
No provider error above. It happens when you use a form control like NgControlName without specifying a parent NgForm or NgFormModel. In most cases, this can be resolved by making sure your form control is within an actual form element. NgForm uses
form as a selector so this will instantiate a new NgForm:
This error happens when you are trying to use a component, provider pipe or directive that has not been imported and added to your ngModule. Whenever you add a new component, provider, pipe or directive to your app, you must add it to the
ngModule in the
src/app/app.module.ts file for Angular to be able to use it. To fix this error you can import the offending component, provider, pipe or directive into the app.module file and then if it is a provider add it to the
providers array and for a component, pipe or directive add it to both the declarations array and