or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

angularjs-integration.mdcomponent-bridging.mddynamic-upgrade.mdindex.mdservice-integration.mdstatic-upgrade.mdtesting-utilities.md
tile.json

angularjs-integration.mddocs/

AngularJS Integration

AngularJS integration utilities provide global configuration and complete TypeScript definitions for seamless interoperability between Angular and AngularJS applications.

Capabilities

Global Configuration

Functions for configuring the AngularJS global object, particularly useful for lazy loading scenarios.

/**
 * Get the current AngularJS global object
 * @returns The AngularJS global object or null if not available
 */
function getAngularJSGlobal(): any;

/**
 * Set the AngularJS global object for lazy loading scenarios
 * @param ng - The AngularJS global object to set
 */
function setAngularJSGlobal(ng: any): void;

/**
 * Get AngularJS library (deprecated - use getAngularJSGlobal)
 * @deprecated Use getAngularJSGlobal() instead
 * @returns The AngularJS global object
 */
function getAngularLib(): any;

/**
 * Set AngularJS library (deprecated - use setAngularJSGlobal)
 * @deprecated Use setAngularJSGlobal() instead
 * @param ng - The AngularJS global object to set
 */
function setAngularLib(ng: any): void;

Usage Example:

import { setAngularJSGlobal, getAngularJSGlobal } from "@angular/upgrade/static";

// Lazy load AngularJS for code splitting
async function loadAngularJS() {
  if (!getAngularJSGlobal()) {
    // Dynamically import AngularJS
    const angularModule = await import("angular");
    setAngularJSGlobal(angularModule.default || angularModule);
  }
  return getAngularJSGlobal();
}

// Use in hybrid application
async function bootstrapHybridApp() {
  const angular = await loadAngularJS();
  
  // Now AngularJS is available for upgrade utilities
  const UpgradeModule = await import("@angular/upgrade/static");
  // ... bootstrap logic
}

TypeScript Definitions

The package provides comprehensive TypeScript definitions for AngularJS integration.

Core Types

/** String token type for AngularJS services */
type Ng1Token = string;

/** AngularJS expression type (string or function) */
type Ng1Expression = string | Function;

/** Injectable definition type */
type IInjectable = (string | Function)[] | Function;

/** Utility type for flexible parameter handling */
type SingleOrListOrMap<T> = T | T[] | {[key: string]: T};

AngularJS Module Interface

/**
 * AngularJS module interface
 */
interface IModule {
  /** Module name */
  name: string;
  
  /** Module dependencies */
  requires: string[];
  
  /** Register animation */
  animation(name: string, animationFactory: Function): IModule;
  
  /** Register config block */
  config(configFn: IInjectable): IModule;
  
  /** Register constant */
  constant(name: string, value: any): IModule;
  
  /** Register controller */
  controller(name: string, controller: IInjectable): IModule;
  
  /** Register directive */
  directive(name: string, directiveFactory: IInjectable): IModule;
  
  /** Register factory */
  factory(name: string, serviceFactory: IInjectable): IModule;
  
  /** Register filter */
  filter(name: string, filterFactory: IInjectable): IModule;
  
  /** Register provider */
  provider(name: string, provider: IInjectable): IModule;
  
  /** Register run block */
  run(initializationFn: IInjectable): IModule;
  
  /** Register service */
  service(name: string, constructor: IInjectable): IModule;
  
  /** Register value */
  value(name: string, value: any): IModule;
  
  /** Register decorator */
  decorator(name: string, decorator: IInjectable): IModule;
  
  /** Register component (AngularJS 1.5+) */
  component(name: string, options: IComponent): IModule;
}

AngularJS Service Interfaces

/**
 * AngularJS $injector service interface
 */
interface IInjectorService {
  get(name: string, caller?: string): any;
  has(name: string): boolean;
  invoke(fn: IInjectable, self?: any, locals?: any): any;
  annotate(fn: IInjectable, strictDi?: boolean): string[];
}

/**
 * AngularJS $rootScope service interface  
 */
interface IRootScopeService extends IScope {
  $new(isolate?: boolean, parent?: IScope): IScope;
  $id: number;
  $parent: IScope;
  $root: IRootScopeService;
}

/**
 * AngularJS scope interface
 */
interface IScope {
  $id: number;
  $parent: IScope;
  $root: IRootScopeService;
  $new(isolate?: boolean, parent?: IScope): IScope;
  $watch(watchExpression: Ng1Expression, listener?: Function, objectEquality?: boolean): Function;
  $watchGroup(watchExpressions: Ng1Expression[], listener: Function): Function;
  $watchCollection(watchExpression: Ng1Expression, listener: Function): Function;
  $digest(): void;
  $apply(exp?: Ng1Expression): any;
  $applyAsync(exp?: Ng1Expression): void;
  $evalAsync(expression?: Ng1Expression, locals?: Object): void;
  $on(name: string, listener: Function): Function;
  $emit(name: string, ...args: any[]): any;
  $broadcast(name: string, ...args: any[]): any;
  $destroy(): void;
  $eval(expression?: Ng1Expression, locals?: Object): any;
  $$destroyed: boolean;
}

/**
 * AngularJS $compile service interface
 */
interface ICompileService {
  (element: Element | string, transclude?: Function, maxPriority?: number): ILinkFn;
}

/**
 * AngularJS $parse service interface
 */
interface IParseService {
  (expression: string): ICompiledExpression;
}

/**
 * AngularJS $controller service interface
 */
interface IControllerService {
  (controllerConstructor: IController, locals?: any, later?: any, ident?: any): any;
}

Component and Directive Interfaces

/**
 * AngularJS directive definition interface
 */
interface IDirective {
  compile?: IDirectiveCompileFn;
  controller?: IController;
  controllerAs?: string;
  bindToController?: boolean | Object;
  link?: IDirectiveLinkFn | IDirectivePrePost;
  name?: string;
  priority?: number;
  replace?: boolean;
  require?: DirectiveRequireProperty;
  restrict?: string;
  scope?: boolean | Object;
  template?: string | Function;
  templateUrl?: string | Function;
  templateNamespace?: string;
  terminal?: boolean;
  transclude?: DirectiveTranscludeProperty;
}

/**
 * AngularJS component definition interface (1.5+)
 */
interface IComponent {
  bindings?: {[key: string]: string};
  controller?: string | IInjectable;
  controllerAs?: string;
  require?: {[key: string]: string} | string[] | string;
  template?: string | Function;
  templateUrl?: string | Function;
  transclude?: boolean | {[key: string]: string};
}

/**
 * AngularJS controller type
 */
type IController = string | IInjectable;

/**
 * AngularJS attributes interface
 */
interface IAttributes {
  $normalize(name: string): string;
  $addClass(classVal: string): void;
  $removeClass(classVal: string): void;
  $updateClass(newClasses: string, oldClasses: string): void;
  $set(key: string, value: any): void;
  $observe(key: string, fn: Function): Function;
  [key: string]: any;
}

/**
 * AngularJS link function interface
 */
interface ILinkFn {
  (scope: IScope, element: IAugmentedJQuery, attrs: IAttributes, 
   controller?: IController, transcludeFn?: ITranscludeFunction): void;
}

/**
 * AngularJS transclude function interface
 */
interface ITranscludeFunction {
  (scope: IScope, cloneAttachFn?: Function, futureParentElement?: any, slotName?: string): IAugmentedJQuery;
  isSlotFilled(slotName: string): boolean;
}

Utility Types

/**
 * Directive require property type
 */
type DirectiveRequireProperty = SingleOrListOrMap<string>;

/**
 * Directive transclude property type  
 */
type DirectiveTranscludeProperty = boolean | string | {[key: string]: string};

/**
 * AngularJS bootstrap configuration interface
 */
interface IAngularBootstrapConfig {
  strictDi?: boolean;
  debugInfoEnabled?: boolean;
}

/**
 * Enhanced jQuery-like interface for AngularJS
 */
interface IAugmentedJQuery {
  [index: number]: Element;
  length: number;
  
  // jQuery-like methods
  addClass(className: string): IAugmentedJQuery;
  after(element: any): IAugmentedJQuery;
  append(element: any): IAugmentedJQuery;
  attr(name: string): string;
  attr(name: string, value: string): IAugmentedJQuery;
  bind(eventType: string, handler: Function): IAugmentedJQuery;
  children(): IAugmentedJQuery;
  clone(): IAugmentedJQuery;
  contents(): IAugmentedJQuery;
  css(propertyName: string): string;
  css(propertyName: string, value: string): IAugmentedJQuery;
  data(): any;
  data(key: string): any;
  data(key: string, value: any): IAugmentedJQuery;
  empty(): IAugmentedJQuery;
  eq(index: number): IAugmentedJQuery;
  find(selector: string): IAugmentedJQuery;
  hasClass(className: string): boolean;
  html(): string;
  html(value: string): IAugmentedJQuery;
  next(): IAugmentedJQuery;
  parent(): IAugmentedJQuery;
  prepend(element: any): IAugmentedJQuery;
  prop(name: string): any;
  prop(name: string, value: any): IAugmentedJQuery;
  ready(handler: Function): IAugmentedJQuery;
  remove(): IAugmentedJQuery;
  removeAttr(name: string): IAugmentedJQuery;
  removeClass(className?: string): IAugmentedJQuery;
  removeData(key?: string): IAugmentedJQuery;
  replaceWith(element: any): IAugmentedJQuery;
  text(): string;
  text(value: string): IAugmentedJQuery;
  toggleClass(className: string): IAugmentedJQuery;
  triggerHandler(eventType: string, extraParameters?: any[]): IAugmentedJQuery;
  unbind(eventType?: string, handler?: Function): IAugmentedJQuery;
  val(): string;
  val(value: string): IAugmentedJQuery;
  wrap(element: any): IAugmentedJQuery;
  
  // AngularJS-specific methods
  controller(name?: string): any;
  injector(): IInjectorService;
  scope(): IScope;
  isolateScope(): IScope;
  inheritedData(key: string): any;
}

Usage in Hybrid Applications

These TypeScript definitions enable full type safety when working with AngularJS in hybrid applications:

import { Component, ElementRef, Injector } from "@angular/core";
import { UpgradeComponent } from "@angular/upgrade/static";

@Component({
  selector: "legacy-wrapper",
  template: ""
})
export class LegacyWrapperComponent extends UpgradeComponent {
  constructor(elementRef: ElementRef, injector: Injector) {
    super("legacyComponent", elementRef, injector);
  }
  
  // Access AngularJS scope with full typing
  ngOnInit() {
    const element = this.elementRef.nativeElement;
    const scope: IScope = angular.element(element).scope();
    const injector: IInjectorService = angular.element(element).injector();
    
    // Type-safe access to AngularJS services
    const $http = injector.get("$http");
    const customService = injector.get("myCustomService");
  }
}