【问题标题】:AngularJS create another module and add it as dependency to firstAngularJS 创建另一个模块并将其作为依赖项添加到 first
【发布时间】:2017-04-30 18:41:40
【问题描述】:

我创建了一个 app.js 文件,这是我的应用程序。 我还使用角度组件创建了一些可用于显示和编辑某些数据的逻辑。简而言之,我创建了 2 个不同的组件(网格、表单)和其他一些子组件,我像使用黑盒子一样使用这些组件。这意味着:在控制器状态下的 Angular 路由中,唯一创建的是一个配置对象,并将其传递给参数等组件。 现在我将这些组件一个一个地包含到我的应用程序中,并希望创建更可重用的东西,例如另一个 Angular 应用程序模块,第二个包含所有组件(黑盒),而我的第一个应用程序唯一需要包含的是第二个模块。这可能吗?

【问题讨论】:

    标签: angularjs module


    【解决方案1】:

    你的意思是这样的?

    angular.module('app', [
       'app.components'
    ])
    
    angular.module('app.components', [
       'app.components.a',
       'app.components.b'
    ])
    
    angular.module('app.components.a', [
       'something.here'
    ])
    
    angular.module('app.components.a').directive('myComponentA', function(){
     return {
        config_here: true
     }
    })
    
    angular.module('app.components.b', [
      'something.here'
    ])
    
    angular.module('app.components.b').directive('myComponentB', function(){
     return {
       config_here: true
     }
    })
    

    我不确定我是否理解正确。此外,您不必用“app.components”包装 component.A 和 component.B。可以将它们作为依赖项直接添加到其他模块或“应用”模块本身,无论您需要什么。

    【讨论】:

      【解决方案2】:

      试试这个代码:

      angular.module('ParentModule', [ 
         'ChildModule_1',
         'ChildModule_2'
      ])
      

      【讨论】:

        猜你喜欢
        • 2023-04-07
        • 1970-01-01
        • 2018-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多