In AngularJS source code, there is a section like this, the comment is added by me
try {
angularModule('ngLocale'); //this detect wether ngLocale has been created
} catch (e) {
//if not created , then create it here
angularModule('ngLocale', []).provider('$locale', $LocaleProvider);
}
I understand how ngLocale
works, because you can override default ngLocale
's $locale
service by using files like
<script src="../src/ngLocale/angular-locale_fr-ca.js"></script>
But this after AngularJS core has been run. Because the exception always throw, literally, why not just remove the detection code, and simply use that instead?
angularModule('ngLocale', []).provider('$locale', $LocaleProvider);
The reason for this is because angularjs lacks the ability to check for the availability of a module on a graceful manner. So instead of a checkModule() or findModule(), the framework needs to induce a "module loading exception" for the nonexistent module.
ensure module could accept a parameter to tell the system if it is OK to not find a module, and simply return null as a result.
Actually, letting the module name to start with a question mark in the var mod = angular.module("?moduleName") code path (and not when defining a module) would make it a simple oneliner code to ommit exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With