refactor($route): move getting the template into its own function

This commit is contained in:
Peter Bacon Darwin
2016-05-24 12:25:16 +01:00
parent b226f3028e
commit 4adc9a9117
+20 -13
View File
@@ -609,19 +609,7 @@ function $RouteProvider() {
$injector.get(value) : $injector.invoke(value, null, null, key);
});
if (angular.isDefined(template = nextRoute.template)) {
if (angular.isFunction(template)) {
template = template(nextRoute.params);
}
} else if (angular.isDefined(templateUrl = nextRoute.templateUrl)) {
if (angular.isFunction(templateUrl)) {
templateUrl = templateUrl(nextRoute.params);
}
if (angular.isDefined(templateUrl)) {
nextRoute.loadedTemplateUrl = $sce.valueOf(templateUrl);
template = $templateRequest(templateUrl);
}
}
template = getTemplateFor(nextRoute);
if (angular.isDefined(template)) {
locals['$template'] = template;
}
@@ -646,6 +634,25 @@ function $RouteProvider() {
}
function getTemplateFor(route) {
var template, templateUrl;
if (angular.isDefined(template = route.template)) {
if (angular.isFunction(template)) {
template = template(route.params);
}
} else if (angular.isDefined(templateUrl = route.templateUrl)) {
if (angular.isFunction(templateUrl)) {
templateUrl = templateUrl(route.params);
}
if (angular.isDefined(templateUrl)) {
route.loadedTemplateUrl = $sce.valueOf(templateUrl);
template = $templateRequest(templateUrl);
}
}
return template;
}
/**
* @returns {Object} the current active route, by matching it against the URL
*/