mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-30 19:34:42 +00:00
add support for $route.reload()
Closes 254
This commit is contained in:
parent
d7686a429c
commit
9fd3dfe49d
2 changed files with 39 additions and 0 deletions
|
|
@ -747,6 +747,20 @@ angularServiceInject('$route', function(location) {
|
||||||
*/
|
*/
|
||||||
otherwise: function(params) {
|
otherwise: function(params) {
|
||||||
$route.when(null, params);
|
$route.when(null, params);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @workInProgress
|
||||||
|
* @ngdoc method
|
||||||
|
* @name angular.service.$route#reload
|
||||||
|
* @methodOf angular.service.$route
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Causes `$route` service to reload (and recreate the `$route.current` scope) upon the next
|
||||||
|
* eval even if {@link angular.service.$location $location} hasn't changed.
|
||||||
|
*/
|
||||||
|
reload: function() {
|
||||||
|
dirty++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function updateRoute(){
|
function updateRoute(){
|
||||||
|
|
|
||||||
|
|
@ -525,6 +525,31 @@ describe("service", function(){
|
||||||
expect($route.current.template).toBe('foo.html');
|
expect($route.current.template).toBe('foo.html');
|
||||||
expect($route.current.scope.$parent).toBe(parentScope);
|
expect($route.current.scope.$parent).toBe(parentScope);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reload routes when reload() is called', function() {
|
||||||
|
var scope = angular.scope(),
|
||||||
|
$location = scope.$service('$location'),
|
||||||
|
$route = scope.$service('$route'),
|
||||||
|
onChangeSpy = jasmine.createSpy('onChange');
|
||||||
|
|
||||||
|
$route.when('', {template: 'foo.html'});
|
||||||
|
$route.onChange(onChangeSpy);
|
||||||
|
expect($route.current).toBeNull();
|
||||||
|
expect(onChangeSpy).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
scope.$eval();
|
||||||
|
|
||||||
|
expect($location.hash).toBe('');
|
||||||
|
expect($route.current.template).toBe('foo.html');
|
||||||
|
expect(onChangeSpy.callCount).toBe(1);
|
||||||
|
|
||||||
|
$route.reload();
|
||||||
|
scope.$eval();
|
||||||
|
|
||||||
|
expect($location.hash).toBe('');
|
||||||
|
expect($route.current.template).toBe('foo.html');
|
||||||
|
expect(onChangeSpy.callCount).toBe(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue