Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ beforeEach(function () {
});
```

## StrictDi and Bootstrap Config
To set the AngularJS strictDi mode, or any future angular.boostrap config parameters, pass in an optional config object called bootstrapConfig:
```js
deferredBootstrapper.bootstrap({
element: document.body,
module: 'MyApp',
bootstrapConfig: {
strictDi: true
},
resolve: {
APP_CONFIG: ['$http', function ($http) {
return $http.get('/api/demo-config');
}]
}
});
```

## License

[MIT](http://opensource.org/licenses/MIT) © Philipp Denzler
14 changes: 10 additions & 4 deletions src/deferred-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function checkConfig (config) {
throw new Error('\'config.resolve\' must be an object.');
}
}
if (config.bootstrapConfig) {
if (!isObject(config.bootstrapConfig)) {
throw new Error('\'config.bootstrapConfig\' must be an object.');
}
}
if (config.moduleResolves) {
if (!isArray(config.moduleResolves)) {
throw new Error('\'config.moduleResolves\' must be an array.');
Expand Down Expand Up @@ -80,11 +85,11 @@ function createInjector (injectorModules, element) {
return angular.injector(modules, element);
}

function doBootstrap (element, module) {
function doBootstrap (element, module, bootstrapConfig) {
var deferred = $q.defer();

angular.element(document).ready(function () {
angular.bootstrap(element, [module]);
angular.bootstrap(element, [module], bootstrapConfig);
removeLoadingClass();

deferred.resolve(true);
Expand All @@ -100,7 +105,8 @@ function bootstrap (configParam) {
injectorModules = config.injectorModules || [],
injector,
promises = [],
constants = [];
constants = [],
bootstrapConfig = config.bootstrapConfig;

bodyElement = angular.element(document.body);

Expand Down Expand Up @@ -139,7 +145,7 @@ function bootstrap (configParam) {
angular.module(moduleName).constant(constantName, result);
});

return doBootstrap(element, module);
return doBootstrap(element, module, bootstrapConfig);
}

function handleError (error) {
Expand Down
30 changes: 30 additions & 0 deletions test/deferred-bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,36 @@ describe('deferredBootstrapper', function () {
}).toThrow('\'config.resolve\' must be an object.');
});

it('should throw if bootstrapConfig is not an object', function () {
var config = {
element: {},
module: 'myModule',
resolve: {
CONST: function () {
}
},
bootstrapConfig: 123
};
expect(function () {
checkConfig(config);
}).toThrow('\'config.bootstrapConfig\' must be an object.');
});

it('should accept valid deferred bootstrap config with bootstrapConfig option', function () {
var config = {
element: {},
module: 'myModule',
resolve: {
CONST: function () {
}
},
bootstrapConfig: {
strictDi: true
}
};
checkConfig(config);
});

it('should throw if moduleResolves is not an array', function () {
var config = {
element: {},
Expand Down