编程语言
首页 > 编程语言> > javascript – ‘未捕获错误:从Angular 4升级到5.0.1时无法解析’运行时错误的所有参数

javascript – ‘未捕获错误:从Angular 4升级到5.0.1时无法解析’运行时错误的所有参数

作者:互联网

这在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中,作者提到他们使用的是静态注射器而不是基于反射的注射器,并且提到不再需要反射聚合物,但在我的情况下它是.

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

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

我希望它也适合你.

标签:javascript,angular,angular-cli,angular5
来源: https://codeday.me/bug/20191002/1841290.html