mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 15:50:22 +00:00
add $route.parent for setting parentScope
This commit is contained in:
parent
6c0cf17404
commit
d7686a429c
2 changed files with 39 additions and 0 deletions
|
|
@ -681,6 +681,23 @@ angularServiceInject('$route', function(location) {
|
|||
*/
|
||||
onChange: bind(onChange, onChange.push),
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue