Skip to content

Commit bad62d8

Browse files
Di PengIgorMinar
Di Peng
authored andcommitted
fix:scope - reintroduce support for eager services
8cad231 broke $eager services Problem is that the injector.eager function is not invoked when a new scope is created. Added a test to make sure service is eagerly instantiated. Closes angular#403
1 parent 65b6e48 commit bad62d8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ function createScope(parent, providers, instanceCache) {
525525
* @param {string} serviceId String ID of the service to return.
526526
* @returns {*} Value, object or function returned by the service factory function if any.
527527
*/
528-
instance.$service = createInjector(instance, providers, instanceCache);
528+
(instance.$service = createInjector(instance, providers, instanceCache)).eager();
529529
}
530530

531531
$log = instance.$service('$log');

test/AngularSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,13 @@ describe('angular', function(){
516516
angular.service('svc2', function(svc1) { return 'svc2-' + svc1; });
517517
expect(angular.scope().$service('svc2')).toEqual('svc2-svc1');
518518
});
519+
520+
it('should eagerly instantiate a service if $eager is true', function() {
521+
var log = [];
522+
angular.service('svc1', function() { log.push('svc1'); }, {$eager: true});
523+
angular.scope();
524+
expect(log).toEqual(['svc1']);
525+
});
519526
});
520527

521528
describe('isDate', function() {

0 commit comments

Comments
 (0)