Skip to content

Commit

Permalink
feat(upgrade): fixes for allow setting the angularjs lib at runtime
Browse files Browse the repository at this point in the history
- always have a value for `angular`, even if no angular is on the page
- use `const` instead of `function` to allow to export a variable `module`
  without breaking tsickle / closure.
  • Loading branch information
tbosch committed Apr 17, 2017
1 parent e927aea commit 90814e4
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions packages/upgrade/src/common/angular1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,21 @@ let angular: {
element: (e: Element | string) => IAugmentedJQuery,
version: {major: number}, resumeBootstrap?: () => void,
getTestability: (e: Element) => ITestabilityService
} = <any>{
bootstrap: noNg,
module: noNg,
element: noNg,
version: noNg,
resumeBootstrap: noNg,
getTestability: noNg
};

try {
if (window.hasOwnProperty('angular')) {
setAngularLib((<any>window).angular);
angular = (<any>window).angular;
}
} catch (e) {
setAngularLib(<any>{
bootstrap: noNg,
module: noNg,
element: noNg,
version: noNg,
resumeBootstrap: noNg,
getTestability: noNg
});
// ignore in CJS mode.
}

/**
Expand All @@ -246,25 +246,17 @@ export function getAngularLib(): any {
return angular;
}

export function bootstrap(
e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void {
angular.bootstrap(e, modules, config);
}
export const bootstrap =
(e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void =>
angular.bootstrap(e, modules, config);

export function module(prefix: string, dependencies?: string[]): IModule {
return angular.module(prefix, dependencies);
}
export const module = (prefix: string, dependencies?: string[]): IModule =>
angular.module(prefix, dependencies);

export function element(e: Element | string): IAugmentedJQuery {
return angular.element(e);
}
export const element = (e: Element | string): IAugmentedJQuery => angular.element(e);

export function resumeBootstrap(): void {
angular.resumeBootstrap();
}
export const resumeBootstrap = (): void => angular.resumeBootstrap();

export function getTestability(e: Element): ITestabilityService {
return angular.getTestability(e);
}
export const getTestability = (e: Element): ITestabilityService => angular.getTestability(e);

export const version = angular.version;

0 comments on commit 90814e4

Please sign in to comment.