Angular migration library facilitating upgrade from AngularJS (v1.x) to Angular (v2+) applications
npx @tessl/cli install tessl/npm-angular--upgrade@20.2.0Angular Upgrade is a migration library that facilitates the upgrade path from AngularJS (v1.x) to modern Angular (v2+) applications. It provides two main approaches: the deprecated dynamic UpgradeAdapter for hybrid applications where both Angular versions can coexist, and the recommended static UpgradeModule approach for more structured migrations.
npm install @angular/upgradeMain package (deprecated):
import { UpgradeAdapter, UpgradeAdapterRef, VERSION } from "@angular/upgrade";Static package (recommended):
import { UpgradeModule, UpgradeComponent, downgradeComponent, downgradeInjectable, downgradeModule } from "@angular/upgrade/static";Testing utilities:
import { createAngularTestingModule, createAngularJSTestingModule } from "@angular/upgrade/static/testing";import { NgModule, Component } from "@angular/core";
import { UpgradeModule, downgradeComponent } from "@angular/upgrade/static";
// Angular component to use in AngularJS
@Component({
selector: "my-angular-component",
template: "<h1>{{title}}</h1>"
})
export class MyAngularComponent {
title = "Hello from Angular!";
}
// Downgrade Angular component for AngularJS
angular.module("myApp").directive("myAngularComponent",
downgradeComponent({ component: MyAngularComponent })
);
// Bootstrap module
@NgModule({
imports: [UpgradeModule],
declarations: [MyAngularComponent],
bootstrap: []
})
export class AppModule {
constructor(private upgrade: UpgradeModule) {}
ngDoBootstrap() {
this.upgrade.bootstrap(document.body, ["myApp"]);
}
}Angular Upgrade is organized around several key components:
UpgradeModule for structured migrationsUpgradeAdapter (deprecated since v5)Recommended approach for hybrid applications with AOT compatibility and better performance.
class UpgradeModule {
constructor(injector: Injector, ngZone: NgZone);
bootstrap(element: Element, modules?: string[], config?: any): void;
readonly $injector: any;
readonly injector: Injector;
readonly ngZone: NgZone;
}Utilities for converting components between Angular and AngularJS frameworks.
function downgradeComponent(info: {
component: Type<any>;
downgradedModule?: string;
propagateDigest?: boolean;
}): any;
abstract class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
constructor(name: string, elementRef: ElementRef, injector: Injector);
}Methods for sharing services and dependency injection between Angular and AngularJS.
function downgradeInjectable(token: any, downgradedModule?: string): Function;
function downgradeModule<T>(
moduleOrBootstrapFn: Type<T> | NgModuleFactory<T> | (() => Promise<NgModuleRef<T>>)
): string;Helper functions for unit testing hybrid applications with mixed Angular/AngularJS dependencies.
function createAngularTestingModule(
angularJSModules: string[],
strictDi?: boolean
): Type<any>;
function createAngularJSTestingModule(angularModules: any[]): string;Legacy dynamic upgrade approach - use static approach for new applications.
class UpgradeAdapter {
downgradeNg2Component(component: Type<any>): Function;
upgradeNg1Component(name: string): Type<any>;
bootstrap(element: Element, modules?: any[], config?: any): UpgradeAdapterRef;
upgradeNg1Provider(name: string, options?: {asToken?: any}): void;
downgradeNg2Provider(token: any): Function;
registerForNg1Tests(modules?: string[]): UpgradeAdapterRef;
}
class UpgradeAdapterRef {
ng1RootScope: any;
ng1Injector: any;
ng2ModuleRef: NgModuleRef<any>;
ng2Injector: Injector;
ready(fn: (upgradeAdapterRef?: UpgradeAdapterRef) => void): void;
dispose(): void;
}Complete TypeScript definitions for AngularJS framework integration.
function getAngularJSGlobal(): any;
function setAngularJSGlobal(ng: any): void;
function getAngularLib(): any; // deprecated
function setAngularLib(ng: any): void; // deprecated;const VERSION: Version;
interface Version {
full: string;
major: string;
minor: string;
patch: string;
}