Skip to content

Commit de3a04a

Browse files
fix(state): Inject $state at runtime to force initialization
Closes #2574
1 parent 36b1348 commit de3a04a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/state.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1469,4 +1469,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
14691469

14701470
angular.module('ui.router.state')
14711471
.factory('$stateParams', function () { return {}; })
1472-
.provider('$state', $StateProvider);
1472+
.provider('$state', $StateProvider)
1473+
// Inject $state to initialize when entering runtime. #2574
1474+
.run(['$injector', function ($injector) {
1475+
// Allow tests (stateSpec.js) to turn this off by defining this constant
1476+
if (!$injector.get("$noAutoInjectStateService")) {
1477+
$injector.get('$state');
1478+
}
1479+
}]);

test/stateSpec.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ describe('state', function () {
22

33
var stateProvider, locationProvider, templateParams, ctrlName, template;
44

5+
angular.module('ui.router').constant("$noAutoInjectStateService", true);
56
beforeEach(module('ui.router', function($locationProvider) {
67
locationProvider = $locationProvider;
78
$locationProvider.html5Mode(false);

0 commit comments

Comments
 (0)