feat(upgrade): fixes for allow setting the angularjs lib at runtime

- 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.
This commit is contained in:
Tobias Bosch 2017-04-14 11:30:12 -07:00
parent e927aeae86
commit 90814e4449
1 changed files with 17 additions and 25 deletions

View File

@ -209,21 +209,21 @@ let angular: {
element: (e: Element | string) => IAugmentedJQuery, element: (e: Element | string) => IAugmentedJQuery,
version: {major: number}, resumeBootstrap?: () => void, version: {major: number}, resumeBootstrap?: () => void,
getTestability: (e: Element) => ITestabilityService getTestability: (e: Element) => ITestabilityService
}; } = <any>{
try {
if (window.hasOwnProperty('angular')) {
setAngularLib((<any>window).angular);
}
} catch (e) {
setAngularLib(<any>{
bootstrap: noNg, bootstrap: noNg,
module: noNg, module: noNg,
element: noNg, element: noNg,
version: noNg, version: noNg,
resumeBootstrap: noNg, resumeBootstrap: noNg,
getTestability: noNg getTestability: noNg
}); };
try {
if (window.hasOwnProperty('angular')) {
angular = (<any>window).angular;
}
} catch (e) {
// ignore in CJS mode.
} }
/** /**
@ -246,25 +246,17 @@ export function getAngularLib(): any {
return angular; return angular;
} }
export function bootstrap( export const bootstrap =
e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void { (e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void =>
angular.bootstrap(e, modules, config); angular.bootstrap(e, modules, config);
}
export function module(prefix: string, dependencies?: string[]): IModule { export const module = (prefix: string, dependencies?: string[]): IModule =>
return angular.module(prefix, dependencies); angular.module(prefix, dependencies);
}
export function element(e: Element | string): IAugmentedJQuery { export const element = (e: Element | string): IAugmentedJQuery => angular.element(e);
return angular.element(e);
}
export function resumeBootstrap(): void { export const resumeBootstrap = (): void => angular.resumeBootstrap();
angular.resumeBootstrap();
}
export function getTestability(e: Element): ITestabilityService { export const getTestability = (e: Element): ITestabilityService => angular.getTestability(e);
return angular.getTestability(e);
}
export const version = angular.version; export const version = angular.version;