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

Commit 38db2d4

Browse files
Ken Sheedlopetebacondarwin
Ken Sheedlo
authored andcommitted
docs(error/$injector/unpr): inadvertently redefining a module can cause error
Closes #8421
1 parent 41cb588 commit 38db2d4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/content/error/$injector/unpr.ngdoc

+30
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,33 @@ angular.module('myApp', [])
2525
// Do something with myService
2626
}]);
2727
```
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

Comments
 (0)