mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-13 08:59:54 +08:00
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:
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user