diff options
| author | Igor Minar | 2011-01-31 23:48:04 -0800 |
|---|---|---|
| committer | Igor Minar | 2011-02-01 09:35:19 -0800 |
| commit | d7686a429c43fd031a0d39788973f726d74bdb33 (patch) | |
| tree | 07a3e56cc0f773cc1f8b77a8f665d534fb48cfab | |
| parent | 6c0cf17404e8e6de0c398fff8e71497f39090408 (diff) | |
| download | angular.js-d7686a429c43fd031a0d39788973f726d74bdb33.tar.bz2 | |
add $route.parent for setting parentScope
| -rw-r--r-- | src/services.js | 17 | ||||
| -rw-r--r-- | test/servicesSpec.js | 22 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/services.js b/src/services.js index d6a7fb0a..b549292f 100644 --- a/src/services.js +++ b/src/services.js @@ -684,6 +684,23 @@ angularServiceInject('$route', function(location) { /** * @workInProgress * @ngdoc method + * @name angular.service.$route#parent + * @methodOf angular.service.$route + * + * @param {Scope} [scope=rootScope] Scope to be used as parent for newly created + * `$route.current.scope` scopes. + * + * @description + * Sets a scope to be used as the parent scope for scopes created on route change. If not + * set, defaults to the root scope. + */ + parent: function(scope) { + if (scope) parentScope = scope; + }, + + /** + * @workInProgress + * @ngdoc method * @name angular.service.$route#when * @methodOf angular.service.$route * diff --git a/test/servicesSpec.js b/test/servicesSpec.js index ddad5d89..91a5389a 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -503,6 +503,28 @@ describe("service", function(){ expect($route.current.template).toBe('bar.html'); expect(onChangeSpy.callCount).toBe(1); }); + + it('should make parentScope configurable via parent()', function() { + var scope = angular.scope(), + parentScope = scope.$new(), + $location = scope.$service('$location'), + $route = scope.$service('$route'); + + $route.parent(parentScope); + $route.when('/foo', {template: 'foo.html'}); + $route.otherwise({template: '404.html'}); + + scope.$eval(); + + expect($route.current.template).toBe('404.html'); + expect($route.current.scope.$parent).toBe(parentScope); + + $location.updateHash('/foo'); + scope.$eval(); + + expect($route.current.template).toBe('foo.html'); + expect($route.current.scope.$parent).toBe(parentScope); + }); }); |
