12

我正在将 angular-cli 项目与 AngularJS 项目结合起来以缓慢升级应用程序。AngularJS 应用程序已经使用 TypeScript,我让 cli 处理捆绑应用程序。我已经松散地遵循了 Victor Savkin 的shell 升级指南和 AngularJS 指南的官方更新,但遇到了错误。

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)
4

1 回答 1

21

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

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

setAngularJSGlobal(angular);

历史注释:该函数以前被命名为setAngularLib.

于 2017-08-30T22:42:54.123 回答