ui-mask
ui-mask copied to clipboard
config provider name is incorrect
Name of registered provider is uiMask.Config so in config blocks it has to be referred to as uiMask.ConfigProvider.
This limits the possibilities of accessing it in config blocks to explicit annotation like this:
angular
.module('myModule')
.config(['uiMask.ConfigProvider', uiMaskConfigProvider => {
Object.keys(uiMaskConfigProvider) // ['$get', 'maskDefinitions', 'clearOnBlur'...]
}])
but an attempt to use implicit annotation (and possibly ng-annotate or its successor babel-plugin-angularjs-annotate) fails:
angular
.module('myModule')
.config(uiMaskConfigProvider => {
'ngInject';
Object.keys(uiMaskConfigProvider) // ['$get']
})
To be able to do that uiMask.Config should become uiMaskConfig. But then uiMaskConfig (value) has to be renamed or provider has to produce the value (which I was certain it did, but it turns out that uiMaskConfig and uiMask.Config are 2 distinct DI entities)
I suggest uiMaskConfig should become uiMaskConfigDefaults and uiMask.Config should be renamed to uiMaskConfig.
It's a breaking change, yet one easy to guide the users through.
Totally agree. In the mean time, we can work around the issue by using $injector to get uiMask.ConfigProvider.
angular
.module('myModule')
.config($injector => {
'ngInject';
const uiMaskConfigProvider = $injector.get("uiMask.ConfigProvider");
Object.keys(uiMaskConfigProvider) // ['$get', 'maskDefinitions', 'clearOnBlur'...]
})
$injector is a service. It won't be available in the config phase
It's what I thought originally. I'm not really understand the way Angular work myself, but the above code is working. And it seems there are 2 different, separate $injector in angular, one is responsible for injecting the providers, one is for services.
More detail here: https://github.com/angular/angular.js/issues/5559
I also did a test, if you inject an $injector in the config block, and compare that with the $injector you get from all other controller (including the run block), you will find that the $injector in the config block is different from all the others (all controllers get the same $injector, but not the config block).