If you don't use a type as key for the provider but instead a string or OpaqueToken you need to pass the key to @Inject()constructor( @Inject('CFG_STRING') /* @Optional()*/ cfgString: CFG_STRING ) {并提供类似的内容 providers: [ {provide: 'CFG_STRING', useValue: CFG_STRING} ], CFG_STRING不是类型,因此不能用作键.您可以使用一些字符串,也可以提及OpaqueToken.它可以是任何字符串,只需在provide和@Inject() CFG_STRING is not a type and can therefore not be used as key. Either you use some string or mentioned an OpaqueToken. It can be any string, it just needs to match between provide and @Inject() 这篇关于我如何获得angular2依赖注入以与价值提供者一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 14:27