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,
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.
}
/**
@ -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;