Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function isModuleDefined #16569

Open
1 of 3 tasks
linjianhong opened this issue May 18, 2018 · 2 comments
Open
1 of 3 tasks

function isModuleDefined #16569

linjianhong opened this issue May 18, 2018 · 2 comments

Comments

@linjianhong
Copy link

@linjianhong linjianhong commented May 18, 2018

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:
When redefine module, orgin module lost.

Expected / new behavior:
Override a module, or do something whether the modele is defined or not.

Minimal reproduction of the problem with instructions:
none

AngularJS version: 1.x.y
all

Browser: [all]

Anything else:
before the code:

      if (requires && modules.hasOwnProperty(name)) {
        modules[name] = null;
      }

add:

      if(isBoolean(requires)){
        return modules.hasOwnProperty(name);
      }

then I can user like this:

      if(angular.module('my-module', true)){
        // codes
      }
      else{
        // codes if not exit module 'my-module'
      }
@gkalpak
Copy link
Member

@gkalpak gkalpak commented May 18, 2018

If we decided to implement this, we should not overload the angular.module() helper, but introduce a new one (e.g. angular.hasModule('<module-name>')). But given that writing your own helper is very easy (and taking into account that AngularJS is just about to enter LTS), I would lean towards not adding it. You can create it yourself like this:

angular.hasModule = function hasModule(moduleName) {
  try {
    angular.module(moduleName);
    return true;
  } catch (_ignored) {
    return false;
  }
};

@linjianhong
Copy link
Author

@linjianhong linjianhong commented May 22, 2018

In fact, I did exactly the same. It's just that this hack doesn't look elegant enough. Usually, I try not to let the code of the catch block run.
Thank you so much!

@petebacondarwin petebacondarwin removed this from the 1.7.x milestone Sep 19, 2018
@petebacondarwin petebacondarwin added this to the 1.7.x - won't fix milestone Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants