Multiple Module in Angularjs

后端 未结 5 1289
-上瘾入骨i
-上瘾入骨i 2020-12-02 20:26

Is it possible to create multiple module in an Angular Script? I went through the documentation and learned that it is some kind of main method concept.

I need examp

5条回答
  •  执笔经年
    2020-12-02 20:48

    Yes, you can define multiple modules in angularJS as given below.

    var myApp = angular.module('myApp', [])
    var myApp2 = angular.module('myApp2', [])
    

    However, don't forget to define the dependency during each module declarations as below. Let's assume myApp2 dependent on myApp. Hence, the declaration would be something similar to,

    var myApp = angular.module('myApp', [])
    var myApp2 = angular.module('myApp2', ['myApp'])
    

    The modularization in AngularJS helps us to keep the code clarity and easy to understand, as we can combine multiple modules to generate the application. However, we need to keep in mind that, we should modularize the components based on their functionality not by their types.

提交回复
热议问题