AngularJS v1.x在混合的angular-cli应用程序中没有加载。

14

我正在将一个angular-cli项目与AngularJS项目结合起来,逐步升级应用程序。AngularJS应用程序已经使用TypeScript,我让cli处理应用程序的捆绑。我大致遵循了Victor Savkin的shell upgrade guide和官方的Updating from AngularJS guide,但是遇到了错误。

当在下面的模块中调用ngDoBootstrap时,一个promise被拒绝,并出现以下错误。

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    UpgradeModule,
    SharedModule,
    CoreModule,
    AppRoutingModule,
  ],
  entryComponents: [ AppComponent ],
})
export class AppModule {

  constructor(private upgrade: UpgradeModule) { }

  ngDoBootstrap() {
    this.upgrade.bootstrap(document.body, [ng1AppModule], { strictDi: true });
  }
}

导致错误

 core.es5.js:1020 ERROR Error: AngularJS v1.x is not loaded!
     at Object.noNg (static.es5.js:15)
     at module$1 (static.es5.js:55)
     at UpgradeModule.webpackJsonp.../../../upgrade/@angular/upgrade/static.es5.js.UpgradeModule.bootstrap
 (static.es5.js:1249)
     at AppModule.webpackJsonp.../../../../../src/app/app.module.ts.AppModule.ngDoBootstrap
 (app.module.ts:51)
     at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_._moduleDoBootstrap
 (core.es5.js:4549)
     at core.es5.js:4508
     at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke
 (zone.js:392)
     at Object.onInvoke (core.es5.js:3890)
     at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke
 (zone.js:391)
     at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.run (zone.js:142)
1个回答

24

@angular/upgrade/static 库公开了一个名为 setAngularJSGlobal 的函数。您可以使用它将 AngularJS 加载到 Angular 库中。

import * as angular from 'angular';
import { setAngularJSGlobal } from '@angular/upgrade/static';

setAngularJSGlobal(angular);

历史记录:该函数先前的名称为setAngularLib


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接