设置混合AngularJS/Angular应用程序时出现"无法解析所有参数"错误

Røy*_*øye 13 angular2-upgrade angular

我想升级我的传统Angular JS应用程序,我一直在关注angular.io的文档来设置混合应用程序.

现在我在app.ts中的bootstrapping过程看起来像:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from "./app.module";
platformBrowserDynamic().bootstrapModule(AppModule);
Run Code Online (Sandbox Code Playgroud)

我的新app.module.ts看起来像:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UpgradeModule } from '@angular/upgrade/static';

@NgModule({
  imports: [
  BrowserModule,
  UpgradeModule
]})
export class AppModule {
  constructor(private upgrade: UpgradeModule) { }
  ngDoBootstrap() {
    this.upgrade.bootstrap(document.body, ['myApp'], { strictDi: true });
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行该应用程序时,我收到以下错误:

compiler.es5.js:1503 Uncaught Error: Can't resolve all parameters for AppModule: (?).
at syntaxError (compiler.es5.js:1503)
at CompileMetadataResolver._getDependenciesMetadata (compiler.es5.js:14780)
at CompileMetadataResolver._getTypeMetadata (compiler.es5.js:14648)
at CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:14489)
at JitCompiler._loadModules (compiler.es5.js:25561)
at JitCompiler._compileModuleAndComponents (compiler.es5.js:25520)
at JitCompiler.compileModuleAsync (compiler.es5.js:25482)
at PlatformRef_._bootstrapModuleWithZone (core.es5.js:4786)
at PlatformRef_.bootstrapModule (core.es5.js:4772)
at Object.map../af (app.ts:487)
Run Code Online (Sandbox Code Playgroud)

在我看来,Angular无法找到UpgradeModule以解决AppModule中的依赖关系.

我的问题是:我是否遗漏了我的引导过程中的某些内容以解决此问题?

(注意:它可能相关也可能不相关,但我使用webpack作为我的模块加载器.)

Ada*_*ler 16

我刚刚遇到同样的问题,经过一段时间的尝试(并查看你的回购)我觉得这是因为我的emitDecoratorMetadata没有在tsconfig中设置

  • 然后在谷歌搜索的最后一轮几乎自杀,我找到了你的答案。你救了我的命。谢谢。 (4认同)