mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix($injector): allow a constructor function to return a function
This change makes `$injector.instantiate` (and thus `$provide.service`) to behave the same as native `new` operator.
This commit is contained in:
parent
dba566a96d
commit
c22adbf160
2 changed files with 11 additions and 1 deletions
|
|
@ -759,7 +759,7 @@ function createInjector(modulesToLoad) {
|
|||
instance = new Constructor();
|
||||
returnedValue = invoke(Type, instance, locals);
|
||||
|
||||
return isObject(returnedValue) ? returnedValue : instance;
|
||||
return isObject(returnedValue) || isFunction(returnedValue) ? returnedValue : instance;
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -788,6 +788,16 @@ describe('injector', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should allow constructor to return a function', function() {
|
||||
var fn = function() {};
|
||||
var Class = function() {
|
||||
return fn;
|
||||
};
|
||||
|
||||
expect($injector.instantiate(Class)).toBe(fn);
|
||||
});
|
||||
|
||||
|
||||
it('should handle constructor exception', function() {
|
||||
expect(function() {
|
||||
$injector.instantiate(function() { throw 'MyError'; });
|
||||
|
|
|
|||
Loading…
Reference in a new issue