5
votes

//index.html
<html ng-app="app">

//app.js
angular.module('app', 'test-module')

If I don't register the test-module in any of my scripts like below:
angular.module('test-module', [])

I will get errors below in brower and the whole website will not be loaded:
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module test-module due to:
Error: [$injector:nomod] Module 'test-module' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.


Q: How to ensure the website page will be loaded even through there are any unknown modules loaded errors ?

2
I think window.load will help you to know that your website is loadedJust code
@dholakiyaankit Perhaps I didn't say clearly or you didn't understand my meaning. When I get this error, the whole web page can't be rendered to us, in other words, what we see in brower is blank page. I want to get the original page whether there are errors.just4fun
ok but for that you have to give use source codeJust code
@dholakiyaankit give you the source code? Isn't the bold words in the question above ?just4fun

2 Answers

0
votes

I think you should look on this problem from other side.

If you use test-module (module for testing) you in development process. You could configure your backend for work in several environments. For example dev, test and prod. You can handle sub domain and decide on backend which modules need to be loaded. dev.yourdomain.com (for dev environment), yourdomain.com (for production environment) and test.yourdomain.com (for tasting).

You can generate such script:

<script type="text/javascript">
    var MyModules = ['test-module'];
</script>

And handle it so:

angular.module.apply(angular, 'app', MyModules);
0
votes

I found solution to you answer :)

Angular have array of requires for each module, so you can easily push some requires if you want to use this module.

In your case you can do this

//index.html
<html ng-app="app">

//app.js
angular.module('app', [])

//test-module.js
angular.module('test-module', [])
angular.module('app').requires.push('test-module');

So if you load test-module.js to your browser, you automatically inject dependency to your app.