AngularJS v1x。未在混合 angular-cli 应用程序中加载
AngularJS v1x. is not loaded in hybrid angular-cli app
我正在将 angular-cli 项目与 AngularJS 项目结合起来,以缓慢升级应用程序。 AngularJS 应用程序已经使用 TypeScript,我让 cli 处理捆绑应用程序。我大致遵循了 Victor Savkin 的 shell upgrade guide and the official 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 (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)
@angular/upgrade/static
库公开了一个 setAngularJSGlobal
函数。您可以使用它来将 AngularJS 加载到 Angular 库中。
import * as angular from 'angular';
import { setAngularJSGlobal } from '@angular/upgrade/static';
setAngularJSGlobal(angular);
历史记录:该函数以前被命名为setAngularLib
。
我正在将 angular-cli 项目与 AngularJS 项目结合起来,以缓慢升级应用程序。 AngularJS 应用程序已经使用 TypeScript,我让 cli 处理捆绑应用程序。我大致遵循了 Victor Savkin 的 shell upgrade guide and the official 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 (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)
@angular/upgrade/static
库公开了一个 setAngularJSGlobal
函数。您可以使用它来将 AngularJS 加载到 Angular 库中。
import * as angular from 'angular';
import { setAngularJSGlobal } from '@angular/upgrade/static';
setAngularJSGlobal(angular);
历史记录:该函数以前被命名为setAngularLib
。