Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

javascript - AngularJS defining angular.module() multiple times

What is the behaviour of calling angular.module('myModule') multiple times?

For example, I wish to define my routes and my directives in separate .js files.

Is this safe?

eg:

//routes.js
angular.module('app',['$strap'])
   .config(function($routeProvider, $locationProvider) {
     ...
   });

//directives.js
angular.module('app')
    .directive('formInput', function() {
...

Also, what is the impact of defining the dependencies multiple times? Is this additive, or last-in-wins?

eg:

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

angular.module(name[, requires], configFn);
...
requires(optional) – {Array.=} – If specified then new module is being created. If unspecified then the the module is being retrieved for further configuration. -- angular.module docs

I would interpret that as follows: you can only define the dependencies once -- the first time you call angular.module for a particular module. You can call angular.module() multiple times after that, but the requires option must not be specified.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...