angularjs - Angular app with more than one module and general functionality -



angularjs - Angular app with more than one module and general functionality -

angular modules kind of namespacing feature know .net world. maintain things contained in modules.

the problem this:

i pages don't have specific client-side functionality utilize custom directives define ng-app or ng-app="xyz" work; don't want introduce additional javascript code(file) create work.

i have pages different modules i.e. app.main , app.specific; both of these pages should utilize same directives #1 , utilize them.

i contain general stuff within app.general module, , have additional modules mentioned app.main , app.specific.

question

which module should directives defined in , how should dependencies (if @ don't phone call each other's code in way) between these modules directives and pages work expected?

if understanding question correctly, suggestion define several angular app modules in same javascript file , activate appropriate 1 each page ng-app="app.general" directive vs ng-app="app.specific". have have single concatenated javascript file contains:

angular.js any 3rd party dependencies using your custom directives, services, controllers, etc i suggest using "very granular modules" recommended @ nyc angularjs meetup feb 2014 @ 24m in video , putting each individual directive , service it's own module. but fine grouping shared directives single module called "app.directives", example. your general code defined angular.module('app.general', ['mydirective']); (plus additional dependencies) your specific code defined angular.module('app.specific', ['mydirective', 'myservice']); (plus additional dependencies)

also note don't have declare app dependencies literal array of strings. var directives = ['dir1', 'dir2']; angular.module('app.specific', directives.concat('myservice', 'mycontroller')); express specific app uses same directives general app.

each page include same <script src="/bundle.js"></script> html (thus loaded web 1 time cached).

general pages include ng-app="app.general" in html. specific pages have ng-app="app.specific".

certain pages don't have specific client-side functionality utilize custom directives

so directives technically constitute "client side functionality" since rendered final html in browser. need load angular.js, modules containing directives , @ to the lowest degree 1 line of own code define app , declare it's dependencies on modules provide custom directives using.

angularjs module

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -