add support for $route.reload()

Closes 254
This commit is contained in:
Igor Minar 2011-02-01 07:43:09 -08:00
parent d7686a429c
commit 9fd3dfe49d
2 changed files with 39 additions and 0 deletions

View file

@ -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(){

View file

@ -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);
});
});