@@ -35,12 +35,24 @@ function $RouteProvider(){
35
35
* - `controller` – `{(string|function()=}` – Controller fn that should be associated with newly
36
36
* created scope or the name of a {@link angular.Module#controller registered controller}
37
37
* if passed as a string.
38
- * - `template` – `{string=}` – html template as a string that should be used by
39
- * {@link ng.directive:ngView ngView} or
38
+ * - `template` – `{string=|function()= }` – html template as a string or function that returns
39
+ * an html template as a string which should be used by {@link ng.directive:ngView ngView} or
40
40
* {@link ng.directive:ngInclude ngInclude} directives.
41
- * this property takes precedence over `templateUrl`.
42
- * - `templateUrl` – `{string=}` – path to an html template that should be used by
43
- * {@link ng.directive:ngView ngView}.
41
+ * This property takes precedence over `templateUrl`.
42
+ *
43
+ * If `template` is a function, it will be called with the following parameters:
44
+ *
45
+ * - `{Array.<Object>}` - route parameters extracted from the current
46
+ * `$location.path()` by applying the current route
47
+ *
48
+ * - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html
49
+ * template that should be used by {@link ng.directive:ngView ngView}.
50
+ *
51
+ * If `templateUrl` is a function, it will be called with the following parameters:
52
+ *
53
+ * - `{Array.<Object>}` - route parameters extracted from the current
54
+ * `$location.path()` by applying the current route
55
+ *
44
56
* - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
45
57
* be injected into the controller. If any of these dependencies are promises, they will be
46
58
* resolved and converted to a value before the controller is instantiated and the
@@ -395,9 +407,18 @@ function $RouteProvider(){
395
407
values . push ( isString ( value ) ? $injector . get ( value ) : $injector . invoke ( value ) ) ;
396
408
} ) ;
397
409
if ( isDefined ( template = next . template ) ) {
410
+ if ( isFunction ( template ) ) {
411
+ template = template ( next . params ) ;
412
+ }
398
413
} else if ( isDefined ( template = next . templateUrl ) ) {
399
- template = $http . get ( template , { cache : $templateCache } ) .
400
- then ( function ( response ) { return response . data ; } ) ;
414
+ if ( isFunction ( template ) ) {
415
+ template = template ( next . params ) ;
416
+ }
417
+ if ( isDefined ( template ) ) {
418
+ next . loadedTemplateUrl = template ;
419
+ template = $http . get ( template , { cache : $templateCache } ) .
420
+ then ( function ( response ) { return response . data ; } ) ;
421
+ }
401
422
}
402
423
if ( isDefined ( template ) ) {
403
424
keys . push ( '$template' ) ;
0 commit comments