Skip to content

Commit d53d134

Browse files
fix(angularjs): Get AngularJS reference using 'getAngularJSGlobal()'
Closes #240 BREAKING CHANGE: If 'angular' variable is not on the window, you must provide it using 'setAngularJSGlobal(angular);'. https://github.com/ui-router/angular-hybrid/wiki/AngularJS-not-found-on-window
1 parent 6c895ce commit d53d134

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/angular-hybrid.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import * as angular from 'angular';
2-
31
import { Component, ElementRef, Inject, Injector, Input, ModuleWithProviders, NgModule } from '@angular/core';
4-
import { downgradeComponent, UpgradeModule } from '@angular/upgrade/static';
2+
import { downgradeComponent, UpgradeModule, getAngularJSGlobal, getAngularLib } from '@angular/upgrade/static';
53

64
import {
75
StateObject,
@@ -35,6 +33,15 @@ import { $InjectorLike, Ng1ViewConfig } from '@uirouter/angularjs';
3533
import { UIRouterRx } from '@uirouter/rx';
3634
import { NgHybridStatesModule } from './interfaces';
3735

36+
const getAngularJS = getAngularJSGlobal || getAngularLib;
37+
const angular = getAngularJS();
38+
39+
if (!angular) {
40+
throw new Error(
41+
'AngularJS not found on window. https://github.com/ui-router/angular-hybrid/wiki/AngularJS-not-found-on-window'
42+
);
43+
}
44+
3845
/**
3946
* Create a ng1 module for the ng1 half of the hybrid application to depend on.
4047
*

0 commit comments

Comments
 (0)