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

前端 未结 7 886
小蘑菇
小蘑菇 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:41

    I would test for the service instead of the module itself.

    // In controller
    if($injector.has('$route')){
    
    }
    if($injector.has('$state')){
    
    }
    
    // In angular config
    if($injector.has('$routeProvider')){
    
    }
    if($injector.has('$stateProvider')){
    
    }
    

提交回复
热议问题