gpt4 book ai didi

javascript - ' Uncaught Error : Can't resolve all parameters for' runtime error when upgrading from Angular 4 to 5. 0.1

转载 作者:行者123 更新时间:2023-11-29 10:30:29 29 4
gpt4 key购买 nike

这在 Angular 4.x 中很好,但在 Angular 5.0.1 中不行。这个项目是用 Angular CLI 生成的。

compiler.js:466 Uncaught Error: Can't resolve all parameters for RegistrationService: (?).
at syntaxError (compiler.js:466)
at CompileMetadataResolver._getDependenciesMetadata (compiler.js:15546)
at CompileMetadataResolver._getTypeMetadata (compiler.js:15381)
at CompileMetadataResolver._getInjectableMetadata (compiler.js:15361)
at CompileMetadataResolver.getProviderMetadata (compiler.js:15721)
at eval (compiler.js:15632)
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (compiler.js:15592)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15160)
at CompileMetadataResolver.getNgModuleSummary (compiler.js:14998)
syntaxError @ compiler.js:466
CompileMetadataResolver._getDependenciesMetadata @ compiler.js:15546
CompileMetadataResolver._getTypeMetadata @ compiler.js:15381
CompileMetadataResolver._getInjectableMetadata @ compiler.js:15361
CompileMetadataResolver.getProviderMetadata @ compiler.js:15721
(anonymous) @ compiler.js:15632
CompileMetadataResolver._getProvidersMetadata @ compiler.js:15592
CompileMetadataResolver.getNgModuleMetadata @ compiler.js:15160
CompileMetadataResolver.getNgModuleSummary @ compiler.js:14998
(anonymous) @ compiler.js:15086
CompileMetadataResolver.getNgModuleMetadata @ compiler.js:15071
JitCompiler._loadModules @ compiler.js:33486
JitCompiler._compileModuleAndComponents @ compiler.js:33447
JitCompiler.compileModuleAsync @ compiler.js:33363
CompilerImpl.compileModuleAsync @ platform-browser-dynamic.js:230
PlatformRef.bootstrapModule @ core.js:5446
(anonymous) @ main.ts:12
../../../../../src/main.ts @ main.bundle.js:640
__webpack_require__ @ inline.bundle.js:55
1 @ main.bundle.js:670
__webpack_require__ @ inline.bundle.js:55
webpackJsonpCallback @ inline.bundle.js:26
(anonymous) @ main.bundle.js:1

这是构造函数的样子:

     constructor(
private apiHelperService: ApiHelperService
) {
}

类有@Injectable()

    @Injectable()
export class ApiHelperService {

它也已正确导入到模块提供程序中。

providers: [
AuthGuard,
ApiHelperService,

如果我将它更改为这个,那么错误就会消失并且它可以工作,但是它希望你将整个解决方案中的每个构造函数更改为这种语法,我认为这是不正确的。

@Inject(ApiHelperService) private apiHelperService: ApiHelperService

这是我的 tsconfig.json,它确实将 emitDecoratorMetadata 正确设置为 true

{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}

最佳答案

Angular 5 Update blog post作者提到他们使用的是静态注入(inject)器而不是基于反射的注入(inject)器,并提到不再需要反射 polyfill,但在我的例子中是这样。

如果您删除了用于反射的 polyfill,请尝试再次添加它们:

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

我希望它也适合你。

关于javascript - ' Uncaught Error : Can't resolve all parameters for' runtime error when upgrading from Angular 4 to 5. 0.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47313571/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com