aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/services.js14
-rw-r--r--test/servicesSpec.js25
2 files changed, 39 insertions, 0 deletions
diff --git a/src/services.js b/src/services.js
index b549292f..68860e22 100644
--- a/src/services.js
+++ b/src/services.js
@@ -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(){
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index 91a5389a..a081882d 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -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);
+ });
});