From e88dfb734a64aad4dbd402642816781b0e1725ec Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 12 Nov 2011 15:23:30 -0800 Subject: refactor(injector): $injector is no longer a function. - $injector('abc') -> $injector.get('abc'); - $injector(fn) -> $injector.invoke(null, fn); --- example/personalLog/test/personalLogSpec.js | 4 +- src/Angular.js | 14 +- src/Injector.js | 209 +++++++++++++--------------- src/angular-mocks.js | 2 +- src/scenario/Application.js | 2 +- src/scenario/Runner.js | 2 +- src/scenario/dsl.js | 8 +- src/service/compiler.js | 3 +- src/service/filter.js | 2 +- test/AngularSpec.js | 2 +- test/InjectorSpec.js | 63 +++++---- test/markupSpec.js | 2 +- test/scenario/dslSpec.js | 22 +-- test/service/scopeSpec.js | 10 +- test/testabilityPatch.js | 4 +- test/widgetsSpec.js | 10 +- 16 files changed, 181 insertions(+), 178 deletions(-) diff --git a/example/personalLog/test/personalLogSpec.js b/example/personalLog/test/personalLogSpec.js index e103d06d..8c4ab291 100644 --- a/example/personalLog/test/personalLogSpec.js +++ b/example/personalLog/test/personalLogSpec.js @@ -3,8 +3,8 @@ describe('example.personalLog.LogCtrl', function() { function createNotesCtrl() { var injector = angular.injector('ng', 'ngMock'); - var scope = injector('$rootScope'); - scope.$cookies = injector('$cookies'); + var scope = injector.get('$rootScope'); + scope.$cookies = injector.get('$cookies'); return scope.$new(example.personalLog.LogCtrl); } diff --git a/src/Angular.js b/src/Angular.js index 6ee51c57..9c506d78 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -849,12 +849,14 @@ function angularInit(config, document){ function bootstrap(element, modules) { modules = modules || []; modules.unshift(ngModule); - createInjector(modules, angularModule)(['$rootScope', '$compile', '$injector', function(scope, compile, injector){ - scope.$apply(function() { - element.data('$injector', injector); - compile(element)(scope); - }); - }]); + createInjector(modules, angularModule).invoke(null, + ['$rootScope', '$compile', '$injector', function(scope, compile, injector){ + scope.$apply(function() { + element.data('$injector', injector); + compile(element)(scope); + }); + }] + ); } function angularJsConfig(document) { diff --git a/src/Injector.js b/src/Injector.js index fb64abd1..1db79eb8 100644 --- a/src/Injector.js +++ b/src/Injector.js @@ -22,7 +22,7 @@ * * // use the injector to kick of your application * // use the type inference to auto inject arguments, or use implicit injection - * $injector(function($rootScope, $compile, $document){ + * $injector.invoke(null, function($rootScope, $compile, $document){ * $compile($document)($rootScope); * $rootScope.$digest(); * }); @@ -60,21 +60,22 @@ function inferInjectionArgs(fn) { /////////////////////////////////////// /** - * @ngdoc function + * @ngdoc object * @name angular.module.AUTO.$injector * @function * * @description * - * `$injector` function is used to retrieve object instances. Object instances are defined by - * {@link angular.module.AUTO.$provide provider}. + * `$injector` is used to retrieve object instances as defined by + * {@link angular.module.AUTO.$provide provider}, instantiate types, invoke methods, + * and load modules. * * The following always holds true: * *
  *   var $injector = angular.injector();
- *   expect($injector('$injector')).toBe($injector);
- *   expect($injector(function($injector){
+ *   expect($injector.get('$injector')).toBe($injector);
+ *   expect($injector.invoke(null, function($injector){
  *     return $injector;
  *   }).toBe($injector);
  * 
@@ -108,14 +109,6 @@ function inferInjectionArgs(fn) { * * ## Inline * As an array of injection names, where the last item in the array is the function to call. - * - * @param {string, function()} argument If the `argument` is: - * - * - `string`: Retrieve an instance of a named object. If object does not exist, use the provider to create - * a new instance. Calling the method repeatedly with the same name will always return the same - * instance. - * - `function`: Invoke the function. This is a short hand for `$injector.`{@link #invoke invoke(null, argument)}. - * @return the object instance or the return value of the invoked function. */ /** @@ -261,113 +254,116 @@ function inferInjectionArgs(fn) { function createInjector(modulesToLoad, moduleRegistry) { var cache = {}, - $injector = internalInjector(cache), providerSuffix = 'Provider', - providerSuffixLength = providerSuffix.length; + providerSuffixLength = providerSuffix.length, + path = [], + $injector; + + value('$injector', $injector = { + get: getService, + invoke: invoke, + instantiate: instantiate, + loadModule: loadModule + }); + value('$provide', { + service: service, + factory: factory, + value: value + }); + + loadModule(modulesToLoad); + + return $injector; - value('$injector', $injector); - value('$provide', {service: service, factory: factory, value: value}); + //////////////////////////////////// function service(name, provider) { if (isFunction(provider)){ - provider = $injector.instantiate(provider); + provider = instantiate(provider); } if (!provider.$get) { throw Error('Providers must define $get factory method.'); } cache['#' + name + providerSuffix] = provider; - }; - function factory(name, factoryFn) { service(name, { $get:factoryFn }); }; - function value(name, value) { factory(name, valueFn(value)); }; - - function internalInjector(cache) { - var path = []; - - function injector(value) { - switch(typeof value) { - case 'function': - return invoke(null, value); - case 'string': - var instanceKey = '#' + value, - instance = cache[instanceKey]; - if (instance !== undefined || cache.hasOwnProperty(instanceKey)) { - return instance; - } - try { - path.unshift(value); - var providerKey = instanceKey + providerSuffix, - provider = cache[providerKey]; - if (provider) { - return cache[instanceKey] = invoke(provider, provider.$get); - } else { - throw Error("Unknown provider for '" + path.join("' <- '") + "'."); - } - } finally { - path.shift(); - } - case 'object': - if (isArray(value)) { - return invoke(null, value); - } - default: - throw Error('Injector expects name or function.'); - } - } + } - function invoke(self, fn, locals){ - var args = [], - $inject, + function factory(name, factoryFn) { service(name, { $get:factoryFn }); } - length, - key; + function value(name, value) { factory(name, valueFn(value)); } - if (typeof fn == 'function') { - $inject = inferInjectionArgs(fn); - length = $inject.length; + function getService(value) { + if (typeof value !== 'string') { + throw Error('Service name expected'); + } + var instanceKey = '#' + value, + instance = cache[instanceKey]; + if (instance !== undefined || cache.hasOwnProperty(instanceKey)) { + return instance; + } + try { + path.unshift(value); + var providerKey = instanceKey + providerSuffix, + provider = cache[providerKey]; + if (provider) { + return cache[instanceKey] = invoke(provider, provider.$get); } else { - if (isArray(fn)) { - $inject = fn; - length = $inject.length; - fn = $inject[--length]; - } - assertArgFn(fn, 'fn'); + throw Error("Unknown provider for '" + path.join("' <- '") + "'."); } + } finally { + path.shift(); + } + } - while(length--) { - key = $inject[length]; - args.unshift( - locals && locals.hasOwnProperty(key) - ? locals[key] - : injector($inject[length], path) - ); + function invoke(self, fn, locals){ + var args = [], + $inject, + length, + key; + + if (typeof fn == 'function') { + $inject = inferInjectionArgs(fn); + length = $inject.length; + } else { + if (isArray(fn)) { + $inject = fn; + length = $inject.length; + fn = $inject[--length]; } + assertArgFn(fn, 'fn'); + } - switch (self ? -1 : args.length) { - case 0: return fn(); - case 1: return fn(args[0]); - case 2: return fn(args[0], args[1]); - case 3: return fn(args[0], args[1], args[2]); - case 4: return fn(args[0], args[1], args[2], args[3]); - case 5: return fn(args[0], args[1], args[2], args[3], args[4]); - case 6: return fn(args[0], args[1], args[2], args[3], args[4], args[5]); - case 7: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - case 8: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); - case 9: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); - case 10: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); - default: return fn.apply(self, args); - } - }; - - injector.invoke = invoke; - injector.instantiate = function(Type, locals){ - var Constructor = function(){}, - instance; - Constructor.prototype = Type.prototype; - instance = new Constructor(); - return invoke(instance, Type, locals) || instance; - }; - injector.loadModule = loadModule; - return injector; + while(length--) { + key = $inject[length]; + args.unshift( + locals && locals.hasOwnProperty(key) + ? locals[key] + : getService($inject[length], path) + ); + } + + // Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke + switch (self ? -1 : args.length) { + case 0: return fn(); + case 1: return fn(args[0]); + case 2: return fn(args[0], args[1]); + case 3: return fn(args[0], args[1], args[2]); + case 4: return fn(args[0], args[1], args[2], args[3]); + case 5: return fn(args[0], args[1], args[2], args[3], args[4]); + case 6: return fn(args[0], args[1], args[2], args[3], args[4], args[5]); + case 7: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + case 8: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); + case 9: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); + case 10: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); + default: return fn.apply(self, args); + } + } + + function instantiate(Type, locals){ + var Constructor = function(){}, + instance; + Constructor.prototype = Type.prototype; + instance = new Constructor(); + return invoke(instance, Type, locals) || instance; } function loadModule(modulesToLoad){ @@ -380,15 +376,10 @@ function createInjector(modulesToLoad, moduleRegistry) { } } if (isFunction(module) || isArray(module)) { - $injector(module); + invoke(null, module); } else { assertArgFn(module, 'module'); } }); } - - - loadModule(modulesToLoad); - - return $injector; } diff --git a/src/angular-mocks.js b/src/angular-mocks.js index ae0ba65e..f5907a42 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -783,7 +783,7 @@ window.jasmine && (function(window){ return function(){ var injector = this.$injector; if (!injector) { - injector = this.$injector = angular.injector('ng', 'ngMock'); + injector = this.$injector = angular.injector('ng', 'ngMock'); } for(var i = 0, ii = blockFns.length; i < ii; i++) { injector.invoke(this, blockFns[i]); diff --git a/src/scenario/Application.js b/src/scenario/Application.js index f4f4b974..5e7b8370 100644 --- a/src/scenario/Application.js +++ b/src/scenario/Application.js @@ -92,7 +92,7 @@ angular.scenario.Application.prototype.executeAction = function(action) { } var element = $window.angular.element($window.document); var $injector = element.inheritedData('$injector'); - $injector(function($browser){ + $injector.invoke(null, function($browser){ $browser.notifyWhenNoOutstandingRequests(function() { action.call(self, $window, _jQuery($window.document)); }); diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js index 5839fae0..aeb5196a 100644 --- a/src/scenario/Runner.js +++ b/src/scenario/Runner.js @@ -163,7 +163,7 @@ angular.scenario.Runner.prototype.createSpecRunner_ = function(scope) { */ angular.scenario.Runner.prototype.run = function(application) { var self = this; - var $root = angular.injector('ng')('$rootScope'); + var $root = angular.injector('ng').get('$rootScope'); angular.extend($root, this); angular.forEach(angular.scenario.Runner.prototype, function(fn, name) { $root[name] = angular.bind(self, fn); diff --git a/src/scenario/dsl.js b/src/scenario/dsl.js index 8963f889..12cbdb21 100644 --- a/src/scenario/dsl.js +++ b/src/scenario/dsl.js @@ -103,25 +103,25 @@ angular.scenario.dsl('browser', function() { api.url = function() { return this.addFutureAction('$location.url()', function($window, $document, done) { - done(null, $window.angular.injector('ng')('$location').url()); + done(null, $window.angular.injector('ng').get('$location').url()); }); }; api.path = function() { return this.addFutureAction('$location.path()', function($window, $document, done) { - done(null, $window.angular.injector('ng')('$location').path()); + done(null, $window.angular.injector('ng').get('$location').path()); }); }; api.search = function() { return this.addFutureAction('$location.search()', function($window, $document, done) { - done(null, $window.angular.injector('ng')('$location').search()); + done(null, $window.angular.injector('ng').get('$location').search()); }); }; api.hash = function() { return this.addFutureAction('$location.hash()', function($window, $document, done) { - done(null, $window.angular.injector('ng')('$location').hash()); + done(null, $window.angular.injector('ng').get('$location').hash()); }); }; diff --git a/src/service/compiler.js b/src/service/compiler.js index 781d7b3a..3464a1a0 100644 --- a/src/service/compiler.js +++ b/src/service/compiler.js @@ -143,7 +143,8 @@ function $CompileProvider(){ * - If you are not asking the linking function to clone the template, create the DOM element(s) * before you send them to the compiler and keep this reference around. *
-       *     var scope = angular.injector('ng')(function($rootScope, $compile){
+       *     var $injector = angular.injector('ng');
+       *     var scope = $injector.invoke(null, function($rootScope, $compile){
        *       var element = $compile('

{{total}}

')($rootScope); * }); *
diff --git a/src/service/filter.js b/src/service/filter.js index 4c43be00..dd97851b 100644 --- a/src/service/filter.js +++ b/src/service/filter.js @@ -85,7 +85,7 @@ function $FilterProvider($provide) { this.$get = ['$injector', function($injector) { return function(name) { - return $injector(name + suffix); + return $injector.get(name + suffix); } }]; diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 4579000d..81a4901b 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -386,7 +386,7 @@ describe('angular', function() { expect(angular.injector(function($provide){ $provide.factory('svc1', function() { return 'svc1'; }); $provide.factory('svc2', ['svc1', function(s) { return 'svc2-' + s; }]); - })('svc2')).toEqual('svc2-svc1'); + }).get('svc2')).toEqual('svc2-svc1'); }); }); diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js index 6c0e9668..d39fee13 100644 --- a/test/InjectorSpec.js +++ b/test/InjectorSpec.js @@ -15,16 +15,16 @@ describe('injector', function() { var instance = {}, original = instance; providers('instance', function() { return instance; }); - expect(injector('instance')).toEqual(instance); + expect(injector.get('instance')).toEqual(instance); instance = 'deleted'; - expect(injector('instance')).toEqual(original); + expect(injector.get('instance')).toEqual(original); }); it('should inject providers', function() { providers('a', function() {return 'Mi';}); providers('b', function(mi) {return mi+'sko';}, {$inject:['a']}); - expect(injector('b')).toEqual('Misko'); + expect(injector.get('b')).toEqual('Misko'); }); @@ -47,7 +47,7 @@ describe('injector', function() { providers('s5', function() { log.push('s5'); }); providers('s6', function() { log.push('s6'); }); - injector('s1'); + injector.get('s1'); expect(log).toEqual(['s6', 's5', 's3', 's4', 's2', 's1']); }); @@ -55,7 +55,7 @@ describe('injector', function() { it('should provide useful message if no provider', function() { expect(function() { - injector('idontexist'); + injector.get('idontexist'); }).toThrow("Unknown provider for 'idontexist'."); }); @@ -63,7 +63,7 @@ describe('injector', function() { providers('a', function(idontexist) {return 1;}); providers('b', function(a) {return 2;}); expect(function() { - injector('b'); + injector.get('b'); }).toThrow("Unknown provider for 'idontexist' <- 'a' <- 'b'."); }); @@ -100,7 +100,7 @@ describe('injector', function() { it('should invoke the passed in function with all of the dependencies as arguments', function(){ providers('c', function() {return 3;}); providers('d', function() {return 4;}); - expect(injector(['a', 'b', 'c', 'd', fn])).toEqual(10); + expect(injector.invoke(null, ['a', 'b', 'c', 'd', fn])).toEqual(10); }); @@ -163,7 +163,7 @@ describe('injector', function() { it('should have $injector', function() { var $injector = createInjector(); - expect($injector('$injector')).toBe($injector); + expect($injector.get('$injector')).toBe($injector); }); it('should define module', function() { @@ -176,7 +176,7 @@ describe('injector', function() { }); }, function(valueProvider, fnProvider, serviceProvider) { log += valueProvider.$get() + fnProvider.$get() + serviceProvider.$get(); - }])(function(value, fn, service) { + }]).invoke(null, function(value, fn, service) { log += '->' + value + fn + service; }); expect(log).toEqual('value;function;service;->value;function;service;'); @@ -189,8 +189,8 @@ describe('injector', function() { $injector = createInjector([ angular.extend(function(p) { $provide = p; }, {$inject: ['$provide']}) ]); - expect($injector('$injector')).toBe($injector); - expect($injector('$provide')).toBe($provide); + expect($injector.get('$injector')).toBe($injector); + expect($injector.get('$provide')).toBe($provide); }); @@ -210,9 +210,9 @@ describe('injector', function() { p.value('c', serviceB.$get() + 'C'); }] ]); - expect($injector('a')).toEqual('A'); - expect($injector('b')).toEqual('AB'); - expect($injector('c')).toEqual('ABC'); + expect($injector.get('a')).toEqual('A'); + expect($injector.get('b')).toEqual('AB'); + expect($injector.get('c')).toEqual('ABC'); }); @@ -222,7 +222,7 @@ describe('injector', function() { provide.value('a', 'abc'); }] }); - expect($injector('a')).toEqual('abc'); + expect($injector.get('a')).toEqual('abc'); }); it('should error on invalid madule name', function(){ @@ -237,7 +237,7 @@ describe('injector', function() { it('should configure $provide values', function() { expect(createInjector([function($provide) { $provide.value('value', 'abc'); - }])('value')).toEqual('abc'); + }]).get('value')).toEqual('abc'); }); }); @@ -246,7 +246,7 @@ describe('injector', function() { it('should configure $provide factory function', function() { expect(createInjector([function($provide) { $provide.factory('value', valueFn('abc')); - }])('value')).toEqual('abc'); + }]).get('value')).toEqual('abc'); }); }); @@ -257,7 +257,7 @@ describe('injector', function() { $provide.service('value', { $get: valueFn('abc') }); - }])('value')).toEqual('abc'); + }]).get('value')).toEqual('abc'); }); @@ -269,7 +269,7 @@ describe('injector', function() { }; expect(createInjector([function($provide) { $provide.service('value', Type); - }])('value')).toEqual('abc'); + }]).get('value')).toEqual('abc'); }); }); }); @@ -318,14 +318,14 @@ describe('injector', function() { it('should retrieve by name and cache instance', function() { expect(instance).toEqual({name: 'angular'}); - expect($injector('instance')).toBe(instance); - expect($injector('instance')).toBe(instance); + expect($injector.get('instance')).toBe(instance); + expect($injector.get('instance')).toBe(instance); }); it('should call functions and infer arguments', function() { - expect($injector(function(instance) { return instance; })).toBe(instance); - expect($injector(function(instance) { return instance; })).toBe(instance); + expect($injector.invoke(null, function(instance) { return instance; })).toBe(instance); + expect($injector.invoke(null, function(instance) { return instance; })).toBe(instance); }); }); @@ -342,7 +342,9 @@ describe('injector', function() { it('should invoke method', function() { - expect($injector(function(book, author) { return author + ':' + book;})).toEqual('melville:moby'); + expect($injector.invoke(null, function(book, author) { + return author + ':' + book; + })).toEqual('melville:moby'); expect($injector.invoke($injector, function(book, author) { expect(this).toEqual($injector); return author + ':' + book;})).toEqual('melville:moby'); @@ -350,7 +352,9 @@ describe('injector', function() { it('should invoke method with locals', function() { - expect($injector(function(book, author) { return author + ':' + book;})).toEqual('melville:moby'); + expect($injector.invoke(null, function(book, author) { + return author + ':' + book; + })).toEqual('melville:moby'); expect($injector.invoke($injector, function(book, author, chapter) { expect(this).toEqual($injector); @@ -360,8 +364,9 @@ describe('injector', function() { it('should invoke method which is annotated', function() { - expect($injector(extend(function(b, a) { return a + ':' + b}, {$inject:['book', 'author']}))). - toEqual('melville:moby'); + expect($injector.invoke(null, extend(function(b, a) { + return a + ':' + b + }, {$inject:['book', 'author']}))).toEqual('melville:moby'); expect($injector.invoke($injector, extend(function(b, a) { expect(this).toEqual($injector); return a + ':' + b; @@ -370,7 +375,9 @@ describe('injector', function() { it('should invoke method which is an array of annotation', function() { - expect($injector(function(book, author) { return author + ':' + book;})).toEqual('melville:moby'); + expect($injector.invoke(null, function(book, author) { + return author + ':' + book; + })).toEqual('melville:moby'); expect($injector.invoke($injector, function(book, author) { expect(this).toEqual($injector); return author + ':' + book; diff --git a/test/markupSpec.js b/test/markupSpec.js index 8f68ee82..6b6ba664 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -150,7 +150,7 @@ describe("markups", function() { it('should bind Text with no Bindings', inject(function($compile) { var $rootScope; function newScope (){ - return $rootScope = angular.injector('ng')('$rootScope'); + return $rootScope = angular.injector('ng').get('$rootScope'); } forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) { var element = $compile('
')(newScope()) diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index 29956801..1b0d613c 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -11,7 +11,7 @@ describe("angular.scenario.dsl", function() { angular: new angular.scenario.testing.MockAngular() }; $window.document.data('$injector', $injector); - $root = $injector('$rootScope'); + $root = $injector.get('$rootScope'); $root.emit = function(eventName) { eventLog.push(eventName); }; @@ -162,16 +162,18 @@ describe("angular.scenario.dsl", function() { describe('location', function() { beforeEach(function() { $window.angular.injector = function() { - return function(serviceId) { - if (serviceId == '$location') { - return { - url: function() {return '/path?search=a#hhh';}, - path: function() {return '/path';}, - search: function() {return {search: 'a'};}, - hash: function() {return 'hhh';} - }; + return { + get: function(serviceId) { + if (serviceId == '$location') { + return { + url: function() {return '/path?search=a#hhh';}, + path: function() {return '/path';}, + search: function() {return {search: 'a'};}, + hash: function() {return 'hhh';} + }; + } + throw new Error('unknown service id ' + serviceId); } - throw new Error('unknown service id ' + serviceId); }; }; }); diff --git a/test/service/scopeSpec.js b/test/service/scopeSpec.js index 54c835f5..71a27b33 100644 --- a/test/service/scopeSpec.js +++ b/test/service/scopeSpec.js @@ -285,7 +285,7 @@ describe('Scope', function() { it('should return a function that allows listeners to be unregistered', inject(function($rootScope) { - var root = angular.injector('ng')('$rootScope'), + var root = angular.injector('ng').get('$rootScope'), listener = jasmine.createSpy('watch listener'), listenerRemove; @@ -470,7 +470,7 @@ describe('Scope', function() { it('should add listener for both $emit and $broadcast events', inject(function($rootScope) { var log = '', - root = angular.injector('ng')('$rootScope'), + root = angular.injector('ng').get('$rootScope'), child = root.$new(); function eventFn() { @@ -490,7 +490,7 @@ describe('Scope', function() { it('should return a function that deregisters the listener', inject(function($rootScope) { var log = '', - root = angular.injector('ng')('$rootScope'), + root = angular.injector('ng').get('$rootScope'), child = root.$new(), listenerRemove; @@ -669,7 +669,7 @@ describe('Scope', function() { describe('listener', function() { it('should receive event object', inject(function($rootScope) { - var scope = angular.injector('ng')('$rootScope'), + var scope = angular.injector('ng').get('$rootScope'), child = scope.$new(), event; @@ -685,7 +685,7 @@ describe('Scope', function() { it('should support passing messages as varargs', inject(function($rootScope) { - var scope = angular.injector('ng')('$rootScope'), + var scope = angular.injector('ng').get('$rootScope'), child = scope.$new(), args; diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index ad39e2fd..8150a0a3 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -31,8 +31,8 @@ beforeEach(function() { afterEach(function() { if (this.$injector) { - var $rootScope = this.$injector('$rootScope'); - var $log = this.$injector('$log'); + var $rootScope = this.$injector.get('$rootScope'); + var $log = this.$injector.get('$log'); // release the injector dealoc($rootScope); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 2bb7bac2..82aa4956 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -507,15 +507,15 @@ describe("widget", function() { it('should be possible to nest ng:view in ng:include', inject(function() { var injector = angular.injector('ng', 'ngMock'); - var myApp = injector('$rootScope'); - var $browser = injector('$browser'); + var myApp = injector.get('$rootScope'); + var $browser = injector.get('$browser'); $browser.xhr.expectGET('includePartial.html').respond('view: '); - injector('$location').path('/foo'); + injector.get('$location').path('/foo'); - var $route = injector('$route'); + var $route = injector.get('$route'); $route.when('/foo', {controller: angular.noop, template: 'viewPartial.html'}); - var element = injector('$compile')( + var element = injector.get('$compile')( '
' + 'include: ' + '
')(myApp); -- cgit v1.2.3