[英]Value Provider error while injecting in Angular
I'm trying to create a Value Provider for our Core Framework. 我正在尝试为我们的核心框架创建一个价值提供者。
So i've created thoses 所以我创建了那些
export interface TexteVide {
texte: string;
}
export const TEXTE_VIDE_VALEUR = new InjectionToken<TexteVide>('TEXTE_VIDE_VALEUR');
export const TexteVideValeurParDefaut: TexteVide = {
texte: '(vide)'
};
Then i've set the providers of our Shared Module 然后,我设置了共享模块的提供者
{ provide: TEXTE_VIDE_VALEUR, useValue: TexteVideValeurParDefaut }
And finally i've injected our Shared Module in other Modules of our application to be able to inject TEXTE_VIDE_VALEUR where needed. 最后,我将共享模块注入了应用程序的其他模块中,以便能够在需要时注入TEXTE_VIDE_VALEUR。
but i'm getting Error: Can't resolve all parameters for TestsComponent: (?).
但我收到
Error: Can't resolve all parameters for TestsComponent: (?).
Here is the constructor of the TestsComponent: 这是TestsComponent的构造函数:
constructor(private TEXTE_VIDE_VALEUR: TexteVide) { console.log(TEXTE_VIDE_VALEUR.texte); }
What's wrong in my implementation ? 我的实现有什么问题? or am I missing something ?
还是我错过了什么?
You should use @Inject()
to inject an InjectionToken
: 您应该使用
@Inject()
注入InjectionToken
:
constructor(@Inject(TEXTE_VIDE_VALEUR) private texte: TexteVide) {
console.log(texte.texte);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.