diff options
| -rw-r--r-- | src/Scope.js | 2 | ||||
| -rw-r--r-- | test/AngularSpec.js | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/Scope.js b/src/Scope.js index b2b8cdb4..a63cb8f7 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -525,7 +525,7 @@ function createScope(parent, providers, instanceCache) { * @param {string} serviceId String ID of the service to return. * @returns {*} Value, object or function returned by the service factory function if any. */ - instance.$service = createInjector(instance, providers, instanceCache); + (instance.$service = createInjector(instance, providers, instanceCache)).eager(); } $log = instance.$service('$log'); diff --git a/test/AngularSpec.js b/test/AngularSpec.js index a4d617b6..983e5848 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -516,6 +516,13 @@ describe('angular', function(){ angular.service('svc2', function(svc1) { return 'svc2-' + svc1; }); expect(angular.scope().$service('svc2')).toEqual('svc2-svc1'); }); + + it('should eagerly instantiate a service if $eager is true', function() { + var log = []; + angular.service('svc1', function() { log.push('svc1'); }, {$eager: true}); + angular.scope(); + expect(log).toEqual(['svc1']); + }); }); describe('isDate', function() { |
