fix(ngRoute): allow proto inherited properties in route params object

copy route params with angular.copy before using angular.extend which looks only for enumerable own
properties

Closes #8181
Closes #9731
This commit is contained in:
cmichal
2014-10-21 16:33:47 +02:00
committed by Caitlin Potter
parent 2a2fd14c08
commit b4770582f8
2 changed files with 23 additions and 4 deletions

View File

@@ -141,10 +141,14 @@ function $RouteProvider() {
* Adds a new route definition to the `$route` service.
*/
this.when = function(path, route) {
//copy original route object to preserve params inherited from proto chain
var routeCopy = angular.copy(route);
if (angular.isUndefined(routeCopy.reloadOnSearch)) {
routeCopy.reloadOnSearch = true;
}
routes[path] = angular.extend(
{reloadOnSearch: true},
route,
path && pathRegExp(path, route)
routeCopy,
path && pathRegExp(path, routeCopy)
);
// create redirection for trailing slashes
@@ -155,7 +159,7 @@ function $RouteProvider() {
routes[redirectPath] = angular.extend(
{redirectTo: path},
pathRegExp(redirectPath, route)
pathRegExp(redirectPath, routeCopy)
);
}

View File

@@ -294,6 +294,21 @@ describe('$route', function() {
$rootScope.$digest();
expect($route.current).toBeDefined();
}));
it("should use route params inherited from prototype chain", function() {
function BaseRoute() {}
BaseRoute.prototype.templateUrl = 'foo.html';
module(function($routeProvider) {
$routeProvider.when('/foo', new BaseRoute);
});
inject(function($route, $location, $rootScope) {
$location.path('/foo');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('foo.html');
});
});
});