(SystemJS) Can't resolve all parameters for

在Angular4项目中,当尝试使用依赖注入服务并遇到编译错误'Can't resolve all parameters for'时,通常是因为缺少了对设计类型参数的设计。解决此问题可能需要检查服务的构造函数并确保所有依赖项都被正确地导入和声明。此外,配置编译选项,如在grunt-ts任务中添加相应的编译设置,也可能有助于解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

angular4中添加service的DI注入后,编译后在tomcat下运行,一直提示

(SystemJS) Can't resolve all parameters for TestComponent: (?).
	syntaxError@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:1513:34 [<root>]
	CompileMetadataResolver.prototype._getDependenciesMetadata@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:14790:35 [<root>]
	CompileMetadataResolver.prototype._getTypeMetadata@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:14658:21 [<root>]
	CompileMetadataResolver.prototype.getNonNormalizedDirectiveMetadata@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:14267:19 [<root>]
	CompileMetadataResolver.prototype._getEntryComponentMetadata@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:14911:40 [<root>]
	CompileMetadataResolver.prototype.getNgModuleMetadata/<@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:14494:102 [<root>]
	CompileMetadataResolver.prototype.getNgModuleMetadata@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:14494:53 [<root>]
	JitCompiler.prototype._loadModules@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:25571:41 [<root>]
	JitCompiler.prototype._compileModuleAndComponents@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:25530:47 [<root>]
	JitCompiler.prototype.compileModuleAsync@http://localhost:8080/web/node_modules/@angular/compiler/bundles/compiler.umd.js:25492:16 [<root>]
	PlatformRef_.prototype._bootstrapModuleWithZone@http://localhost:8080/web/node_modules/@angular/core/bundles/core.umd.js:4793:16 [<root>]
	PlatformRef_.prototype.bootstrapModule@http://localhost:8080/web/node_modules/@angular/core/bundles/core.umd.js:4779:16 [<root>]
	@http://localhost:8080/web/main.js:4:1 [<root>]
	@http://localhost:8080/web/main.js:1:31 [<root>]
	@http://localhost:8080/web/main.js:1:2 [<root>]
	scheduleResolveOrReject/<@http://localhost:8080/web/node_modules/zone.js/dist/zone.js:758:52 [<root>]
	drainMicroTaskQueue@http://localhost:8080/web/node_modules/zone.js/dist/zone.js:591:25 [<root>]
	ZoneTask/this.invoke@http://localhost:8080/web/node_modules/zone.js/dist/zone.js:464:25 [<root>]
	
	Evaluating http://localhost:8080/web/main.js
	Error loading http://localhost:8080/web/main.js  index

但在源码环境下运行正常,于是奇怪了。后来想到编译打包使用的grunt-ts,而编译是angular4提供的样例工程自动编译的,这2者会不会有差异。用对比工具对比后发现,还真有差异。

//danielinbiti

首先少了

var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
又少了

__metadata("design:paramtypes", [TestService_1.TestService])
于是就出现了参数无法识别的错误。

看来编译方式还得再调整

在grunt-ts可以增加编译项:

emitDecoratorMetadata:true  danielinbiti

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值