mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +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) {
|
||||
$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(){
|
||||
|
|
|
|||
|
|
@ -525,6 +525,31 @@ describe("service", function(){
|
|||
expect($route.current.template).toBe('foo.html');
|
||||
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