aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2011-01-04 11:53:23 -0800
committerIgor Minar2011-01-04 18:04:00 -0800
commitb2631f61709ae71bb29ec6f1353f2a3c1ad33cd3 (patch)
tree4c955af5f726d29e2d6004d39403d0843f37711e
parent1430c6d6b1f4edf11b1bd877e8907ac8ab0be923 (diff)
downloadangular.js-b2631f61709ae71bb29ec6f1353f2a3c1ad33cd3.tar.bz2
rename scope.$inject to scope.$service
see changelog diff for more info
-rw-r--r--CHANGELOG.md19
-rw-r--r--example/personalLog/test/personalLogSpec.js3
-rw-r--r--src/Angular.js2
-rw-r--r--src/Compiler.js2
-rw-r--r--src/Scope.js20
-rw-r--r--src/validators.js2
-rw-r--r--src/widgets.js2
-rw-r--r--test/AngularSpec.js2
-rw-r--r--test/BinderTest.js16
-rw-r--r--test/ResourceSpec.js8
-rw-r--r--test/ScenarioSpec.js6
-rw-r--r--test/ValidatorsTest.js2
-rw-r--r--test/servicesSpec.js179
-rw-r--r--test/widgetsSpec.js16
14 files changed, 146 insertions, 133 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 12a37c63..e091ec1d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@
not needed.
### Breaking changes
+ - API for accessing registered services — `scope.$inject` — was renamed to
+ [`scope.$service`](http://docs.angularjs.org/#!angular.scope.$service).
+
- Support for `eager-published` services was removed. This change was done to make explicit
dependency declaration always required in order to allow making relatively expensive services
lazily initialized (e.g. $cookie, $location), as well as remove 'magic' and reduce unnecessary
@@ -21,17 +24,17 @@
- $invalidWidgets
To temporarily preserve the 'eager-published' status for these services, you may use `ng:init`
- (e.g. `ng:init="$location = $inject('$location'), ...`) in the view or more correctly create
+ (e.g. `ng:init="$location = $service('$location'), ...`) in the view or more correctly create
a service like this:
angular.service('published-svc-shim', function() {
- this.$location = this.$inject('$location');
- this.$route = this.$inject('$route');
- this.$cookies = this.$inject('$cookies');
- this.$window = this.$inject('$window');
- this.$document = this.$inject('$document');
- this.$exceptionHandler = this.$inject('$exceptionHandler');
- this.$invalidWidgets = this.$inject('$invalidWidgets');
+ this.$location = this.$service('$location');
+ this.$route = this.$service('$route');
+ this.$cookies = this.$service('$cookies');
+ this.$window = this.$service('$window');
+ this.$document = this.$service('$document');
+ this.$exceptionHandler = this.$service('$exceptionHandler');
+ this.$invalidWidgets = this.$service('$invalidWidgets');
}, {$creation: 'eager'});
- In the light of the `eager-published` change, to complete the cleanup we renamed `$creation`
diff --git a/example/personalLog/test/personalLogSpec.js b/example/personalLog/test/personalLogSpec.js
index 8d8eef97..7502ff21 100644
--- a/example/personalLog/test/personalLogSpec.js
+++ b/example/personalLog/test/personalLogSpec.js
@@ -3,8 +3,7 @@ describe('example.personalLog.LogCtrl', function() {
function createNotesCtrl() {
var scope = angular.scope();
- var inject = scope.$inject;
- scope.$cookies = inject('$cookies');
+ scope.$cookies = scope.$service('$cookies');
return scope.$new(example.personalLog.LogCtrl);
}
diff --git a/src/Angular.js b/src/Angular.js
index 991598e1..96d478f3 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -947,7 +947,7 @@ function angularInit(config){
if (config.autobind) {
// TODO default to the source of angular.js
var scope = compile(window.document, _null, {'$config':config}),
- $browser = scope.$inject('$browser');
+ $browser = scope.$service('$browser');
if (config.css)
$browser.addCss(config.base_url + config.css);
diff --git a/src/Compiler.js b/src/Compiler.js
index a98bd502..5a841a25 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -35,7 +35,7 @@ Template.prototype = {
foreach(this.inits, function(fn) {
queue.push(function() {
childScope.$tryEval(function(){
- return childScope.$inject(fn, childScope, element);
+ return childScope.$service(fn, childScope, element);
}, element);
});
});
diff --git a/src/Scope.js b/src/Scope.js
index 27df770d..393e015b 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -578,7 +578,7 @@ function createScope(parent, providers, instanceCache) {
foreach(Class.prototype, function(fn, name){
instance[name] = bind(instance, fn);
});
- instance.$inject.apply(instance, concat([Class, instance], arguments, 1));
+ instance.$service.apply(instance, concat([Class, instance], arguments, 1));
//TODO: backwards compatibility hack, remove when we don't depend on init methods
if (isFunction(Class.prototype.init)) {
@@ -615,7 +615,23 @@ function createScope(parent, providers, instanceCache) {
if (!parent.$root) {
instance.$root = instance;
instance.$parent = instance;
- (instance.$inject = createInjector(instance, providers, instanceCache))();
+
+ /**
+ * @workInProgress
+ * @ngdoc function
+ * @name angular.scope.$service
+ * @function
+ *
+ * @description
+ * Provides access to angular's dependency injector and
+ * {@link angular.service registered services}. In general the use of this api is discouraged,
+ * except for tests and components that currently don't support dependency injection (widgets,
+ * filters, etc).
+ *
+ * @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))();
}
return instance;
diff --git a/src/validators.js b/src/validators.js
index b55db341..3de98d61 100644
--- a/src/validators.js
+++ b/src/validators.js
@@ -383,7 +383,7 @@ extend(angularValidator, {
cache.current = input;
var inputState = cache.inputs[input],
- $invalidWidgets = scope.$inject('$invalidWidgets');
+ $invalidWidgets = scope.$service('$invalidWidgets');
if (!inputState) {
cache.inputs[input] = inputState = { inFlight: true };
diff --git a/src/widgets.js b/src/widgets.js
index a09ee29d..05979281 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -271,7 +271,7 @@ function valueAccessor(scope, element) {
formatterName = element.attr('ng:format') || NOOP,
formatter = angularFormatter(formatterName),
format, parse, lastError, required,
- invalidWidgets = scope.$inject('$invalidWidgets') || {markValid:noop, markInvalid:noop};
+ invalidWidgets = scope.$service('$invalidWidgets') || {markValid:noop, markInvalid:noop};
if (!validator) throw "Validator named '" + validatorName + "' not found.";
if (!formatter) throw "Formatter named '" + formatterName + "' not found.";
format = formatter.format;
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index f5a202fe..6f943af8 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -322,7 +322,7 @@ describe('angular service', function() {
angular.service('fake', function() { return 'old'; });
angular.service('fake', function() { return 'new'; });
- expect(scope.$inject('fake')).toEqual('new');
+ expect(scope.$service('fake')).toEqual('new');
});
it('should preserve $ properties on override', function() {
diff --git a/test/BinderTest.js b/test/BinderTest.js
index c5c81ee9..53a61eb0 100644
--- a/test/BinderTest.js
+++ b/test/BinderTest.js
@@ -515,38 +515,38 @@ BinderTest.prototype.testValidateForm = function() {
var items = [{}, {}];
c.scope.$set("items", items);
c.scope.$eval();
- assertEquals(3, c.scope.$inject('$invalidWidgets').length);
+ assertEquals(3, c.scope.$service('$invalidWidgets').length);
c.scope.$set('name', '');
c.scope.$eval();
- assertEquals(3, c.scope.$inject('$invalidWidgets').length);
+ assertEquals(3, c.scope.$service('$invalidWidgets').length);
c.scope.$set('name', ' ');
c.scope.$eval();
- assertEquals(3, c.scope.$inject('$invalidWidgets').length);
+ assertEquals(3, c.scope.$service('$invalidWidgets').length);
c.scope.$set('name', 'abc');
c.scope.$eval();
- assertEquals(2, c.scope.$inject('$invalidWidgets').length);
+ assertEquals(2, c.scope.$service('$invalidWidgets').length);
items[0].name = 'abc';
c.scope.$eval();
- assertEquals(1, c.scope.$inject('$invalidWidgets').length);
+ assertEquals(1, c.scope.$service('$invalidWidgets').length);
items[1].name = 'abc';
c.scope.$eval();
- assertEquals(0, c.scope.$inject('$invalidWidgets').length);
+ assertEquals(0, c.scope.$service('$invalidWidgets').length);
};
BinderTest.prototype.testValidateOnlyVisibleItems = function(){
var c = this.compile('<div><input name="name" ng:required><input ng:show="show" name="name" ng:required></div>', undefined, jqLite(document.body));
c.scope.$set("show", true);
c.scope.$eval();
- assertEquals(2, c.scope.$inject('$invalidWidgets').length);
+ assertEquals(2, c.scope.$service('$invalidWidgets').length);
c.scope.$set("show", false);
c.scope.$eval();
- assertEquals(1, c.scope.$inject('$invalidWidgets').visible());
+ assertEquals(1, c.scope.$service('$invalidWidgets').visible());
};
BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() {
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js
index cedd87ce..8b78df12 100644
--- a/test/ResourceSpec.js
+++ b/test/ResourceSpec.js
@@ -162,8 +162,8 @@ describe("resource", function() {
it('should excersize full stack', function(){
var scope = angular.compile('<div></div>');
- var $browser = scope.$inject('$browser');
- var $resource = scope.$inject('$resource');
+ var $browser = scope.$service('$browser');
+ var $resource = scope.$service('$resource');
var Person = $resource('/Person/:id');
$browser.xhr.expectGET('/Person/123').respond('\n{\n"name":\n"misko"\n}\n');
var person = Person.get({id:123});
@@ -174,8 +174,8 @@ describe("resource", function() {
it('should return the same object when verifying the cache', function(){
var scope = angular.compile('<div></div>');
- var $browser = scope.$inject('$browser');
- var $resource = scope.$inject('$resource');
+ var $browser = scope.$service('$browser');
+ var $resource = scope.$service('$resource');
var Person = $resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}});
$browser.xhr.expectGET('/Person/123').respond('[\n{\n"name":\n"misko"\n}\n]');
var person = Person.query({id:123});
diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js
index ec016635..30a3d72a 100644
--- a/test/ScenarioSpec.js
+++ b/test/ScenarioSpec.js
@@ -42,7 +42,7 @@ describe("ScenarioSpec: Compilation", function(){
it("should have $ objects", function(){
scope = compile('<div></div>', {$config: {a:"b"}});
- expect(scope.$inject('$location')).toBeDefined();
+ expect(scope.$service('$location')).toBeDefined();
expect(scope.$get('$eval')).toBeDefined();
expect(scope.$get('$config')).toBeDefined();
expect(scope.$get('$config.a')).toEqual("b");
@@ -53,8 +53,8 @@ describe("ScenarioSpec: Compilation", function(){
it("should take location object", function(){
var url = "http://server/#?book=moby";
scope = compile("<div>{{$location}}</div>");
- var $location = scope.$inject('$location');
- var $browser = scope.$inject('$browser');
+ var $location = scope.$service('$location');
+ var $browser = scope.$service('$browser');
expect($location.hashSearch.book).toBeUndefined();
$browser.setUrl(url);
$browser.poll();
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index d6df7184..c59aaf77 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -128,7 +128,7 @@ describe('Validator:asynchronous', function(){
it("should not make second request to same value", function(){
asynchronous.call(self, "kai", function(v,f){value=v; fn=f;});
expect(value).toEqual('kai');
- expect(self.$inject('$invalidWidgets')[0]).toEqual(self.$element);
+ expect(self.$service('$invalidWidgets')[0]).toEqual(self.$element);
var spy = jasmine.createSpy();
asynchronous.call(self, "kai", spy);
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index e7bf39cb..cff79ae4 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -1,5 +1,5 @@
describe("service", function(){
- var scope, $xhrError, $log, mockServices, inject, $browser, $browserXhr, $xhrBulk, $xhr, $route;
+ var scope, $xhrError, $log, mockServices, $browser, $browserXhr, $xhrBulk, $xhr;
beforeEach(function(){
$xhrError = jasmine.createSpy('$xhr.error');
@@ -8,13 +8,10 @@ describe("service", function(){
'$xhr.error': $xhrError,
'$log': $log
});
- inject = scope.$inject;
- $browser = inject('$browser');
+ $browser = scope.$service('$browser');
$browserXhr = $browser.xhr;
- $xhrBulk = scope.$inject('$xhr.bulk');
- $xhr = scope.$inject('$xhr');
- $route = scope.$inject('$route');
- scope.$location = inject('$location');
+ $xhrBulk = scope.$service('$xhr.bulk');
+ $xhr = scope.$service('$xhr');
});
afterEach(function(){
@@ -24,7 +21,7 @@ describe("service", function(){
it("should inject $window", function(){
- expect(scope.$inject('$window')).toEqual(window);
+ expect(scope.$service('$window')).toEqual(window);
});
xit('should add stylesheets', function(){
@@ -45,7 +42,7 @@ describe("service", function(){
function info(){ logger+= 'info;'; }
function error(){ logger+= 'error;'; }
var scope = createScope({}, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}, $document:[{cookie:''}]}),
- $log = scope.$inject('$log');
+ $log = scope.$service('$log');
$log.log();
$log.warn();
$log.info();
@@ -57,7 +54,7 @@ describe("service", function(){
var logger = "";
function log(){ logger+= 'log;'; }
var scope = createScope({}, angularService, {$window: {console:{log:log}}, $document:[{cookie:''}]});
- var $log = scope.$inject('$log');
+ var $log = scope.$service('$log');
$log.log();
$log.warn();
$log.info();
@@ -67,7 +64,7 @@ describe("service", function(){
it('should use noop if no console', function(){
var scope = createScope({}, angularService, {$window: {}, $document:[{cookie:''}]}),
- $log = scope.$inject('$log');
+ $log = scope.$service('$log');
$log.log();
$log.warn();
$log.info();
@@ -115,98 +112,100 @@ describe("service", function(){
it('should log errors', function(){
var error = '';
$log.error = function(m) { error += m; };
- scope.$inject('$exceptionHandler')('myError');
+ scope.$service('$exceptionHandler')('myError');
expect(error).toEqual('myError');
});
});
describe("$location", function(){
- it("should inject $location", function() {
- expect(scope.$location).toBeDefined();
+ var $location;
+
+ beforeEach(function() {
+ $location = scope.$service('$location');
});
it("update should update location object immediately", function() {
var href = 'http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2=';
- scope.$location.update(href);
- expect(scope.$location.href).toEqual(href);
- expect(scope.$location.protocol).toEqual("http");
- expect(scope.$location.host).toEqual("host");
- expect(scope.$location.port).toEqual("123");
- expect(scope.$location.path).toEqual("/p/a/t/h.html");
- expect(scope.$location.search).toEqual({query:'value'});
- expect(scope.$location.hash).toEqual('path?key=value&flag&key2=');
- expect(scope.$location.hashPath).toEqual('path');
- expect(scope.$location.hashSearch).toEqual({key: 'value', flag: true, key2: ''});
+ $location.update(href);
+ expect($location.href).toEqual(href);
+ expect($location.protocol).toEqual("http");
+ expect($location.host).toEqual("host");
+ expect($location.port).toEqual("123");
+ expect($location.path).toEqual("/p/a/t/h.html");
+ expect($location.search).toEqual({query:'value'});
+ expect($location.hash).toEqual('path?key=value&flag&key2=');
+ expect($location.hashPath).toEqual('path');
+ expect($location.hashSearch).toEqual({key: 'value', flag: true, key2: ''});
});
it('toString() should return actual representation', function() {
var href = 'http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2=';
- scope.$location.update(href);
- expect(scope.$location.toString()).toEqual(href);
+ $location.update(href);
+ expect($location.toString()).toEqual(href);
scope.$eval();
- scope.$location.host = 'new';
- scope.$location.path = '';
- expect(scope.$location.toString()).toEqual('http://new:123?query=value#path?key=value&flag&key2=');
+ $location.host = 'new';
+ $location.path = '';
+ expect($location.toString()).toEqual('http://new:123?query=value#path?key=value&flag&key2=');
});
it('toString() should not update browser', function() {
var url = $browser.getUrl();
- scope.$location.update('http://www.angularjs.org');
- expect(scope.$location.toString()).toEqual('http://www.angularjs.org');
+ $location.update('http://www.angularjs.org');
+ expect($location.toString()).toEqual('http://www.angularjs.org');
expect($browser.getUrl()).toEqual(url);
});
it('should update browser at the end of $eval', function() {
var url = $browser.getUrl();
- scope.$location.update('http://www.angularjs.org/');
- scope.$location.update({path: '/a/b'});
- expect(scope.$location.toString()).toEqual('http://www.angularjs.org/a/b');
+ $location.update('http://www.angularjs.org/');
+ $location.update({path: '/a/b'});
+ expect($location.toString()).toEqual('http://www.angularjs.org/a/b');
expect($browser.getUrl()).toEqual(url);
scope.$eval();
expect($browser.getUrl()).toEqual('http://www.angularjs.org/a/b');
});
it('should update hashPath and hashSearch on hash update', function(){
- scope.$location.update('http://server/#path?a=b');
+ $location.update('http://server/#path?a=b');
scope.$eval();
- scope.$location.update({hash: ''});
+ $location.update({hash: ''});
- expect(scope.$location.hashPath).toEqual('');
- expect(scope.$location.hashSearch).toEqual({});
+ expect($location.hashPath).toEqual('');
+ expect($location.hashSearch).toEqual({});
});
it('should update hash on hashPath or hashSearch update', function() {
- scope.$location.update('http://server/#path?a=b');
+ $location.update('http://server/#path?a=b');
scope.$eval();
- scope.$location.update({hashPath: '', hashSearch: {}});
+ $location.update({hashPath: '', hashSearch: {}});
- expect(scope.$location.hash).toEqual('');
+ expect($location.hash).toEqual('');
});
it('should update hashPath and hashSearch on hash property change', function(){
- scope.$location.update('http://server/#path?a=b');
+ $location.update('http://server/#path?a=b');
scope.$eval();
- scope.$location.hash = '';
+ $location.hash = '';
- expect(scope.$location.toString()).toEqual('http://server/');
- expect(scope.$location.hashPath).toEqual('');
- expect(scope.$location.hashSearch).toEqual({});
+ expect($location.toString()).toEqual('http://server/');
+ expect($location.hashPath).toEqual('');
+ expect($location.hashSearch).toEqual({});
});
it('should update hash on hashPath or hashSearch property change', function() {
- scope.$location.update('http://server/#path?a=b');
+ $location.update('http://server/#path?a=b');
scope.$eval();
- scope.$location.hashPath = '';
- scope.$location.hashSearch = {};
+ $location.hashPath = '';
+ $location.hashSearch = {};
- expect(scope.$location.toString()).toEqual('http://server/');
- expect(scope.$location.hash).toEqual('');
+ expect($location.toString()).toEqual('http://server/');
+ expect($location.hash).toEqual('');
});
it('should update hash before any processing', function(){
scope = compile('<div>');
- scope.$location = scope.$inject('$location');
+ scope.$location = scope.$service('$location');
var log = '';
scope.$watch('$location.hash', function(){
log += this.$location.hashPath + ';';
@@ -220,37 +219,37 @@ describe("service", function(){
});
it('udpate() should accept hash object and update only given properties', function() {
- scope.$location.update("http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2=");
- scope.$location.update({host: 'new', port: 24});
+ $location.update("http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2=");
+ $location.update({host: 'new', port: 24});
- expect(scope.$location.host).toEqual('new');
- expect(scope.$location.port).toEqual(24);
- expect(scope.$location.protocol).toEqual('http');
- expect(scope.$location.href).toEqual("http://new:24/p/a/t/h.html?query=value#path?key=value&flag&key2=");
+ expect($location.host).toEqual('new');
+ expect($location.port).toEqual(24);
+ expect($location.protocol).toEqual('http');
+ expect($location.href).toEqual("http://new:24/p/a/t/h.html?query=value#path?key=value&flag&key2=");
});
it('updateHash() should accept one string argument to update path', function() {
- scope.$location.updateHash('path');
- expect(scope.$location.hash).toEqual('path');
- expect(scope.$location.hashPath).toEqual('path');
+ $location.updateHash('path');
+ expect($location.hash).toEqual('path');
+ expect($location.hashPath).toEqual('path');
});
it('updateHash() should accept one hash argument to update search', function() {
- scope.$location.updateHash({a: 'b'});
- expect(scope.$location.hash).toEqual('?a=b');
- expect(scope.$location.hashSearch).toEqual({a: 'b'});
+ $location.updateHash({a: 'b'});
+ expect($location.hash).toEqual('?a=b');
+ expect($location.hashSearch).toEqual({a: 'b'});
});
it('updateHash() should accept path and search both', function() {
- scope.$location.updateHash('path', {a: 'b'});
- expect(scope.$location.hash).toEqual('path?a=b');
- expect(scope.$location.hashSearch).toEqual({a: 'b'});
- expect(scope.$location.hashPath).toEqual('path');
+ $location.updateHash('path', {a: 'b'});
+ expect($location.hash).toEqual('path?a=b');
+ expect($location.hashSearch).toEqual({a: 'b'});
+ expect($location.hashPath).toEqual('path');
});
it('should remove # if hash is empty', function() {
- scope.$location.update('http://www.angularjs.org/index.php#');
- expect(scope.$location.href).toEqual('http://www.angularjs.org/index.php');
+ $location.update('http://www.angularjs.org/index.php#');
+ expect($location.href).toEqual('http://www.angularjs.org/index.php');
});
it('should not change browser\'s url with empty hash', function() {
@@ -266,7 +265,7 @@ describe("service", function(){
scope = compile('<input name="price" ng:required ng:validate="number"></input>');
jqLite(document.body).append(scope.$element);
scope.$init();
- var $invalidWidgets = scope.$inject('$invalidWidgets');
+ var $invalidWidgets = scope.$service('$invalidWidgets');
expect($invalidWidgets.length).toEqual(1);
scope.price = 123;
@@ -292,19 +291,21 @@ describe("service", function(){
describe("$route", function(){
it('should route and fire change event', function(){
- var log = '';
+ var log = '',
+ $location, $route;
+
function BookChapter() {
this.log = '<init>';
}
scope = compile('<div></div>').$init();
- scope.$location = scope.$inject('$location');
- $route = scope.$inject('$route');
+ $location = scope.$service('$location');
+ $route = scope.$service('$route');
$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'});
$route.when('/Blank');
$route.onChange(function(){
log += 'onChange();';
});
- scope.$location.update('http://server#/Book/Moby/Chapter/Intro?p=123');
+ $location.update('http://server#/Book/Moby/Chapter/Intro?p=123');
scope.$eval();
expect(log).toEqual('onChange();');
expect($route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'});
@@ -312,14 +313,14 @@ describe("service", function(){
var lastId = $route.current.scope.$id;
log = '';
- scope.$location.update('http://server#/Blank?ignore');
+ $location.update('http://server#/Blank?ignore');
scope.$eval();
expect(log).toEqual('onChange();');
expect($route.current.params).toEqual({ignore:true});
expect($route.current.scope.$id).not.toEqual(lastId);
log = '';
- scope.$location.update('http://server#/NONE');
+ $location.update('http://server#/NONE');
scope.$eval();
expect(log).toEqual('onChange();');
expect($route.current).toEqual(null);
@@ -330,12 +331,6 @@ describe("service", function(){
});
});
- describe('$resource', function(){
- it('should publish to root scope', function(){
- expect(scope.$inject('$resource')).toBeTruthy();
- });
- });
-
describe('$defer', function() {
var $defer, $exceptionHandler;
@@ -345,9 +340,9 @@ describe("service", function(){
'$exceptionHandler': jasmine.createSpy('$exceptionHandler')
});
- $browser = scope.$inject('$browser');
- $defer = scope.$inject('$defer');
- $exceptionHandler = scope.$inject('$exceptionHandler');
+ $browser = scope.$service('$browser');
+ $defer = scope.$service('$defer');
+ $exceptionHandler = scope.$service('$exceptionHandler');
});
@@ -497,7 +492,7 @@ describe("service", function(){
describe('cache', function(){
var cache;
- beforeEach(function(){ cache = scope.$inject('$xhr.cache'); });
+ beforeEach(function(){ cache = scope.$service('$xhr.cache'); });
it('should cache requests', function(){
$browserXhr.expectGET('/url').respond('first');
@@ -541,7 +536,7 @@ describe("service", function(){
});
it('should keep track of in flight requests and request only once', function(){
- scope.$inject('$xhr.bulk').urls['/bulk'] = {
+ scope.$service('$xhr.bulk').urls['/bulk'] = {
match:function(url){
return url == '/url';
}
@@ -611,7 +606,7 @@ describe("service", function(){
$browser = new MockBrowser();
$browser.cookieHash['preexisting'] = 'oldCookie';
scope = createScope(null, angularService, {$browser: $browser});
- scope.$cookies = scope.$inject('$cookies');
+ scope.$cookies = scope.$service('$cookies');
});
@@ -709,7 +704,7 @@ describe("service", function(){
describe('$cookieStore', function() {
it('should serialize objects to json', function() {
- scope.$inject('$cookieStore').put('objectCookie', {id: 123, name: 'blah'});
+ scope.$service('$cookieStore').put('objectCookie', {id: 123, name: 'blah'});
scope.$eval(); //force eval in test
expect($browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'});
});
@@ -718,12 +713,12 @@ describe("service", function(){
it('should deserialize json to object', function() {
$browser.cookies('objectCookie', '{"id":123,"name":"blah"}');
$browser.poll();
- expect(scope.$inject('$cookieStore').get('objectCookie')).toEqual({id: 123, name: 'blah'});
+ expect(scope.$service('$cookieStore').get('objectCookie')).toEqual({id: 123, name: 'blah'});
});
it('should delete objects from the store when remove is called', function() {
- scope.$inject('$cookieStore').put('gonner', { "I'll":"Be Back"});
+ scope.$service('$cookieStore').put('gonner', { "I'll":"Be Back"});
scope.$eval(); //force eval in test
expect($browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'});
});
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index cfda67d1..98dd3480 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -551,9 +551,9 @@ describe("widget", function(){
scope.childScope = createScope();
scope.childScope.name = 'misko';
scope.url = 'myUrl';
- scope.$inject('$xhr.cache').data.myUrl = {value:'{{name}}'};
+ scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'};
scope.$init();
- scope.$inject('$browser').defer.flush();
+ scope.$service('$browser').defer.flush();
expect(element.text()).toEqual('misko');
dealoc(scope);
});
@@ -564,9 +564,9 @@ describe("widget", function(){
scope.childScope = createScope();
scope.childScope.name = 'igor';
scope.url = 'myUrl';
- scope.$inject('$xhr.cache').data.myUrl = {value:'{{name}}'};
+ scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'};
scope.$init();
- scope.$inject('$browser').defer.flush();
+ scope.$service('$browser').defer.flush();
expect(element.text()).toEqual('igor');
@@ -581,9 +581,9 @@ describe("widget", function(){
var element = jqLite('<ng:include src="url" scope="this"></ng:include>');
var scope = angular.compile(element);
scope.url = 'myUrl';
- scope.$inject('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'};
+ scope.$service('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'};
scope.$init();
- scope.$inject('$browser').defer.flush();
+ scope.$service('$browser').defer.flush();
// this one should really be just '1', but due to lack of real events things are not working
// properly. see discussion at: http://is.gd/ighKk
@@ -598,9 +598,9 @@ describe("widget", function(){
expect(scope.loaded).not.toBeDefined();
scope.url = 'myUrl';
- scope.$inject('$xhr.cache').data.myUrl = {value:'my partial'};
+ scope.$service('$xhr.cache').data.myUrl = {value:'my partial'};
scope.$init();
- scope.$inject('$browser').defer.flush();
+ scope.$service('$browser').defer.flush();
expect(element.text()).toEqual('my partial');
expect(scope.loaded).toBe(true);
dealoc(element);