Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Altered routing to allow interpolation of params into templateUrl

added test for same
commit dc9be174af2f6e8d55b798209dfb9235f390b934 1 parent d6706ef
Jamie Pate authored
Showing with 36 additions and 1 deletion.
  1. +9 −1 src/ng/route.js
  2. +27 −0 test/ng/routeSpec.js
View
10 src/ng/route.js
@@ -420,7 +420,15 @@ function $RouteProvider(){
if (!match && (params = matcher($location.path(), path))) {
match = inherit(route, {
params: extend({}, $location.search(), params),
- pathParams: params});
+ pathParams: params
+ });
+ if ((route.templateUrl) && (/:/.test(route.templateUrl))) {
+ match.templateUrl = interpolate(route.templateUrl,params);
+ }
+ //remove cached template if params were substituted (rely on browser cache)
+ if (match.templateUrl != route.templateUrl) {
+ match.template = undefined;
+ }
match.$route = route;
}
});
View
27 test/ng/routeSpec.js
@@ -318,6 +318,33 @@ describe('$route', function() {
});
});
+ it('should interpolate parameters into the url of fetched templates',function(){
+ module(function($routeProvider) {
+ $routeProvider.
+ when('/foo/:rparam',{templateUrl:':rparam.html'});
+ });
+
+ inject(function($route, $httpBackend, $location, $rootScope) {
+ var log = '';
+ $rootScope.$on('$routeChangeStart', function(e, next) { log += '$before(' + next.templateUrl + ');'});
+ $rootScope.$on('$routeChangeSuccess', function(e, next) { log += '$after(' + next.templateUrl + ');'});
+
+ $httpBackend.expectGET('r1.html').respond('R1');
+ $httpBackend.expectGET('r2.html').respond('R2');
+
+ $location.path('/foo/r1');
+ $rootScope.$digest();
+ expect(log).toBe('$before(r1.html);');
+
+ $location.path('/foo/r2');
+ $rootScope.$digest();
+ expect(log).toBe('$before(r1.html);$before(r2.html);');
+
+ $httpBackend.flush();
+ expect(log).toBe('$before(r1.html);$before(r2.html);$after(r2.html);');
+ expect(log).not.toContain('$after(r1.html);');
+ });
+ });
it('should not update $routeParams until $routeChangeSuccess', function() {
module(function($routeProvider) {

1 comment on commit dc9be17

@EvanSmithMSMD

Hello,

This is GREAT!! I must have a dynamic generated templateUrl, due to the nature of the project I am on. We have a old C++ application that is generating dynamic html pages and thus never a static page is generated.

Is this fix going to make it into the main thread of Angular? Please put it in.

If not how do I fork and put it in myself? I only include one javascript file (angular.js), but this change is in several files.

Thanks,
Evna

Please sign in to comment.
Something went wrong with that request. Please try again.