mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 19:40:56 +08:00
fix($injector): throw when factory $get method does not return a value
BREAKING CHANGE: Previously, not returning a value would fail silently, and an application trying to inject the value owuld inject an undefined value, quite possibly leading to a TypeError. Now, the application will fail entirely, and a reason will be given. Closes #4575 Closes #9210
This commit is contained in:
33
docs/content/error/$injector/undef.ngdoc
Normal file
33
docs/content/error/$injector/undef.ngdoc
Normal file
@@ -0,0 +1,33 @@
|
||||
@ngdoc error
|
||||
@name $injector:undef
|
||||
@fullName Undefined Value
|
||||
@description
|
||||
|
||||
This error results from registering a factory which does not return a value (or whose return value is undefined).
|
||||
|
||||
The following is an example of a factory which will throw this error upon injection:
|
||||
|
||||
```js
|
||||
angular.module("badModule", []).
|
||||
factory("badFactory", function() {
|
||||
doLotsOfThings();
|
||||
butDontReturnAValue();
|
||||
});
|
||||
```
|
||||
|
||||
In order to prevent the error, return a value of some sort, such as an object which exposes an API for working
|
||||
with the injected object.
|
||||
|
||||
```js
|
||||
angular.module("goodModule", []).
|
||||
factory("goodFactory", function() {
|
||||
doLotsOfThings();
|
||||
butDontReturnAValue();
|
||||
|
||||
return {
|
||||
doTheThing: function methodThatDoesAThing() {
|
||||
}
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user