Multiple Module in Angularjs

后端 未结 5 1297
-上瘾入骨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:41

    Of course you can. Just use angular.module('moduleName', [/* dependencies */]) as many times as the # of your modules you wish to create.

    To get a reference to a previously defined module just do: var myModule = angular.module('moduleName'); and then myModule.controller(...), myModule.config(), myModule.constant() etc.

    A suggested project layout (see Angular Seed) has a module for your app, then another for your controllers, another for your services, another for your filters and yet another for your directives. Of course this is a mere suggestion. Others suggest alternative layouts.

提交回复
热议问题