填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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.