diff options
| author | Luis Ramón López | 2012-11-03 21:11:07 +0100 |
|---|---|---|
| committer | Misko Hevery | 2013-01-18 21:20:49 -0800 |
| commit | faf02f0c4db7962f863b0da2a82c8cafab2c706f (patch) | |
| tree | 9602f0d265d47ee0018a03654cee0f68b1c83488 /src/ng/route.js | |
| parent | b8bd4d5460d9952e9a3bb14992636b17859bd457 (diff) | |
| download | angular.js-faf02f0c4db7962f863b0da2a82c8cafab2c706f.tar.bz2 | |
feat(route): Allow using functions as template params in 'when'
Diffstat (limited to 'src/ng/route.js')
| -rw-r--r-- | src/ng/route.js | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/ng/route.js b/src/ng/route.js index 91e4adb3..971caa1c 100644 --- a/src/ng/route.js +++ b/src/ng/route.js @@ -35,12 +35,24 @@ function $RouteProvider(){ * - `controller` – `{(string|function()=}` – Controller fn that should be associated with newly * created scope or the name of a {@link angular.Module#controller registered controller} * if passed as a string. - * - `template` – `{string=}` – html template as a string that should be used by - * {@link ng.directive:ngView ngView} or + * - `template` – `{string=|function()=}` – html template as a string or function that returns + * an html template as a string which should be used by {@link ng.directive:ngView ngView} or * {@link ng.directive:ngInclude ngInclude} directives. - * this property takes precedence over `templateUrl`. - * - `templateUrl` – `{string=}` – path to an html template that should be used by - * {@link ng.directive:ngView ngView}. + * This property takes precedence over `templateUrl`. + * + * If `template` is a function, it will be called with the following parameters: + * + * - `{Array.<Object>}` - route parameters extracted from the current + * `$location.path()` by applying the current route + * + * - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html + * template that should be used by {@link ng.directive:ngView ngView}. + * + * If `templateUrl` is a function, it will be called with the following parameters: + * + * - `{Array.<Object>}` - route parameters extracted from the current + * `$location.path()` by applying the current route + * * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should * be injected into the controller. If any of these dependencies are promises, they will be * resolved and converted to a value before the controller is instantiated and the @@ -395,9 +407,18 @@ function $RouteProvider(){ values.push(isString(value) ? $injector.get(value) : $injector.invoke(value)); }); if (isDefined(template = next.template)) { + if (isFunction(template)) { + template = template(next.params); + } } else if (isDefined(template = next.templateUrl)) { - template = $http.get(template, {cache: $templateCache}). - then(function(response) { return response.data; }); + if (isFunction(template)) { + template = template(next.params); + } + if (isDefined(template)) { + next.loadedTemplateUrl = template; + template = $http.get(template, {cache: $templateCache}). + then(function(response) { return response.data; }); + } } if (isDefined(template)) { keys.push('$template'); |
