How to check for the existence of a module without an error being raised?

前端 未结 7 898
小蘑菇
小蘑菇 2020-12-24 01:04

In Angular 1.2, ngRoute is a separate module so you can use other community routers like ui.router instead.

I\'m writing an open-source mod

7条回答
  •  孤城傲影
    2020-12-24 01:43

    If you decorate angular.module to store the names in an array then you could just check if the array contains your module name.

    Decorate angular.module

    See @dsfq's answer on SO.

    This needs to happen after angular is loaded but before you start loading any angular modules.

    Check for your module

    if(angular.modules.indexOf("ngRoute") > -1) ...

提交回复
热议问题