填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

NG2003: No suitable injection token for parameter
对于参数,没有合适的注入令牌

说明

Description

在编译时,没有找到针对某个构造函数参数的注入令牌。InjectionToken是可以在依赖注入提供者中使用的令牌。

There is no injection token for a constructor parameter at compile time. InjectionTokens are tokens that can be used in a Dependency Injection Provider.


如何排除本错误

Debugging the error

查看引发错误的参数及其在该类中的所有用法。用 stringnumberbooleanObject 定义参数时,通常会引发此错误。

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.

用来自 @angular/core@Injectable 方法或 @Inject 装饰器,以确保对你要注入的类型进行具体化(让它具有运行期间表示形式)。确保将某个提供者添加到此装饰器,以免抛出NG0201:未找到提供者错误。

Use the @Injectable method or @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.