Skip to content

Commit 90814e4

Browse files
committed
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.
1 parent e927aea commit 90814e4

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

packages/upgrade/src/common/angular1.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,21 @@ let angular: {
209209
element: (e: Element | string) => IAugmentedJQuery,
210210
version: {major: number}, resumeBootstrap?: () => void,
211211
getTestability: (e: Element) => ITestabilityService
212+
} = <any>{
213+
bootstrap: noNg,
214+
module: noNg,
215+
element: noNg,
216+
version: noNg,
217+
resumeBootstrap: noNg,
218+
getTestability: noNg
212219
};
213220

214221
try {
215222
if (window.hasOwnProperty('angular')) {
216-
setAngularLib((<any>window).angular);
223+
angular = (<any>window).angular;
217224
}
218225
} catch (e) {
219-
setAngularLib(<any>{
220-
bootstrap: noNg,
221-
module: noNg,
222-
element: noNg,
223-
version: noNg,
224-
resumeBootstrap: noNg,
225-
getTestability: noNg
226-
});
226+
// ignore in CJS mode.
227227
}
228228

229229
/**
@@ -246,25 +246,17 @@ export function getAngularLib(): any {
246246
return angular;
247247
}
248248

249-
export function bootstrap(
250-
e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void {
251-
angular.bootstrap(e, modules, config);
252-
}
249+
export const bootstrap =
250+
(e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void =>
251+
angular.bootstrap(e, modules, config);
253252

254-
export function module(prefix: string, dependencies?: string[]): IModule {
255-
return angular.module(prefix, dependencies);
256-
}
253+
export const module = (prefix: string, dependencies?: string[]): IModule =>
254+
angular.module(prefix, dependencies);
257255

258-
export function element(e: Element | string): IAugmentedJQuery {
259-
return angular.element(e);
260-
}
256+
export const element = (e: Element | string): IAugmentedJQuery => angular.element(e);
261257

262-
export function resumeBootstrap(): void {
263-
angular.resumeBootstrap();
264-
}
258+
export const resumeBootstrap = (): void => angular.resumeBootstrap();
265259

266-
export function getTestability(e: Element): ITestabilityService {
267-
return angular.getTestability(e);
268-
}
260+
export const getTestability = (e: Element): ITestabilityService => angular.getTestability(e);
269261

270262
export const version = angular.version;

0 commit comments

Comments
 (0)