【发布时间】:2019-12-28 18:58:47
【问题描述】:
我想在现有的angularjs 项目中开始使用 Angular 组件,我想使用downgradeModule 创建一个混合的Angular/AngularJS 应用程序。
我已经能够使用 main.ts 文件中的代码降级我的 angular 组件:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { downgradeModule } from '@angular/upgrade/static';
import { AppModule } from '../new-app/src/app/app.module';
const bootstrapFn = (extraProviders: StaticProvider[]) => {
const platformRef = platformBrowserDynamic(extraProviders);
return platformRef.bootstrapModule(AppModule);
};
const downgradedModule = downgradeModule(bootstrapFn);
angular.module('old.angular.js.app', [..., downgradedModule])
虽然在使用 ng build 和 ng serve 命令时一切正常,但 prod 模式存在问题 - 当我运行 AppModule 时不会生成 AppModule 的编译 js 代码(我无法将其视为已编译 main.{hash}.js 文件的一部分)。
我怀疑这是因为 AppModule 是按需引导的,但我不知道如何解决这个问题并让这个模块编译。
目前,由于 AppModule 尚未编译,我的 angularjs 应用程序中出现此错误
Error: [$injector:modulerr] Failed to instantiate module old.angular.js.app due to:
Error: [$injector:modulerr] Failed to instantiate module old.angular.js.app.newmodule due to:
Error: [$injector:nomod] Module 'old.angular.js.app.newmodule' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
【问题讨论】:
标签: angular angular-cli angular-hybrid