Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ce669ed

Browse files
ghodssbtford
ghodss
authored andcommitted
docs(guide): warn about module creation versus retrieval
Updated Module documentation to include the suggestion of the top-rated comment: "This documentation should warn that "angular.module('myModule', [])" always creates a new module, but "angular.module('myModule')" always retrieves an existing reference."
1 parent a3aa418 commit ce669ed

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/content/guide/module.ngdoc

+18
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ scripts into a VM. There are existing projects which deal with script loading, w
191191
with Angular. Because modules do nothing at load time they can be loaded into the VM in any order
192192
and thus script loaders can take advantage of this property and parallelize the loading process.
193193

194+
## Creation versus Retrieval
195+
196+
Beware that using `angular.module('myModule', [])` will create the module `myModule` and overwrite any
197+
existing module named `myModule`. Use `angular.module('myModule')` to retrieve an existing module.
198+
199+
<pre>
200+
var myModule = angular.module('myModule', []);
201+
202+
// add some directives and services
203+
myModule.service('myService', ...);
204+
myModule.directive('myDirective', ...);
205+
206+
// overwrites both myService and myDirective by creating a new module
207+
var myModule = angular.module('myModule', []);
208+
209+
// throws an error because myOtherModule has yet to be defined
210+
var myModule = angular.module('myOtherModule');
211+
</pre>
194212

195213
# Unit Testing
196214

0 commit comments

Comments
 (0)