@@ -25,3 +25,33 @@ angular.module('myApp', [])
25
25
// Do something with myService
26
26
}]);
27
27
```
28
+
29
+ An unknown provider error can also be caused by accidentally redefining a
30
+ module using the `angular.module` API, as shown in the following example.
31
+
32
+ ```
33
+ angular.module('myModule', [])
34
+ .service('myCoolService', function () { /* ... */ });
35
+
36
+ angular.module('myModule', [])
37
+ // myModule has already been created! This is not what you want!
38
+ .directive('myDirective', ['myCoolService', function (myCoolService) {
39
+ // This directive definition throws unknown provider, because myCoolService
40
+ // has been destroyed.
41
+ }]);
42
+ ```
43
+
44
+ To fix this problem, make sure you only define each module with the
45
+ `angular.module(name, [requires])` syntax once across your entire project.
46
+ Retrieve it for subsequent use with `angular.module(name)`. The fixed example
47
+ is shown below.
48
+
49
+ ```
50
+ angular.module('myModule', [])
51
+ .service('myCoolService', function () { /* ... */ });
52
+
53
+ angular.module('myModule')
54
+ .directive('myDirective', ['myCoolService', function (myCoolService) {
55
+ // This directive definition does not throw unknown provider.
56
+ }]);
57
+ ```
0 commit comments