You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -44,7 +44,7 @@ To make it possible to conditionally show a loading indicator or an error messag
44
44
Have a look at the demo pages to see this in action.
45
45
46
46
## Advanced usage
47
-
You can have multiple constants resolved for your app and you can do in the resolve function whatever is necessary before the app is started. The only constraint is, that the function has to return a promise. It is important to note, that the arguments passed to your resolve functions are NOT dependency injected. You get access to the following services in the resolve function: $http, $q, injector
47
+
You can have multiple constants resolved for your app and you can do in the resolve function whatever is necessary before the app is started. The only constraint is, that the function has to return a promise.
48
48
49
49
To handle exceptions when the promises are resolved, you can add an onError function to the configuration object.
var deferred =$q.defer(), $timeout =injector.get('$timeout');
59
+
}],
60
+
OTHER_CONSTANT:['$http', '$q', '$timeout', function ($http, $q, $timeout) {
61
+
var deferred =$q.defer();
62
62
$timeout(function () {
63
63
deferred.resolve('MyConstant');
64
64
}, 2000);
65
65
returndeferred.promise;
66
-
}
66
+
}]
67
67
},
68
68
onError:function (error) {
69
69
alert('Could not bootstrap, error: '+ error);
70
70
}
71
71
});
72
72
```
73
73
74
+
## Custom injector modules
75
+
By default, the injector that calls your resolve functions only provides the services from the AngularJS core module (ng). If you have a use case where you want to use one of your existing services to get configuration at bootstrap time, you can specify which modules should be made available and inject services from those modules in the resolve function. An example is below:
76
+
77
+
```js
78
+
deferredBootstrapper.bootstrap({
79
+
element:document.body,
80
+
module:'myApp',
81
+
injectorModules:'myApp.settings',
82
+
resolve: {
83
+
SETTINGS: ['SettingsService', function (SettingsService) {
84
+
returnSettingsService.get('/settings');
85
+
}]
86
+
}
87
+
});
88
+
```
89
+
90
+
The ```injectorModules``` option can also take an array of modules. If you have multiple services spread across different modules you can also inject them:
91
+
92
+
```js
93
+
deferredBootstrapper.bootstrap({
94
+
element:document.body,
95
+
module:'myApp',
96
+
injectorModules: ['myApp.settings', 'myApp.foo']
97
+
resolve: {
98
+
SETTINGS: ['SettingsService', function (SettingsService) {
99
+
returnSettingsService.get('/settings');
100
+
}],
101
+
FOO: ['FooService', function (FooService) {
102
+
returnFooService.get('/foo');
103
+
}]
104
+
}
105
+
});
106
+
```
107
+
74
108
## Testing
75
109
Since the constants that deferredBootstrapper adds to your applications module are not available in your unit tests, it makes sense to provide them in a global beforeEach():
0 commit comments