Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

config provider name is incorrect #230

Open
jrencz opened this issue Sep 21, 2017 · 3 comments
Open

config provider name is incorrect #230

jrencz opened this issue Sep 21, 2017 · 3 comments

Comments

@jrencz
Copy link

jrencz commented Sep 21, 2017

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.

@leminh111
Copy link

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'...]
  })

@jrencz
Copy link
Author

jrencz commented Feb 28, 2018

$injector is a service. It won't be available in the config phase

@leminh111
Copy link

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: angular/angular.js#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).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants