Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4adc9a9

Browse files
refactor($route): move getting the template into its own function
1 parent b226f30 commit 4adc9a9

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/ngRoute/route.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -609,19 +609,7 @@ function $RouteProvider() {
609609
$injector.get(value) : $injector.invoke(value, null, null, key);
610610
});
611611

612-
if (angular.isDefined(template = nextRoute.template)) {
613-
if (angular.isFunction(template)) {
614-
template = template(nextRoute.params);
615-
}
616-
} else if (angular.isDefined(templateUrl = nextRoute.templateUrl)) {
617-
if (angular.isFunction(templateUrl)) {
618-
templateUrl = templateUrl(nextRoute.params);
619-
}
620-
if (angular.isDefined(templateUrl)) {
621-
nextRoute.loadedTemplateUrl = $sce.valueOf(templateUrl);
622-
template = $templateRequest(templateUrl);
623-
}
624-
}
612+
template = getTemplateFor(nextRoute);
625613
if (angular.isDefined(template)) {
626614
locals['$template'] = template;
627615
}
@@ -646,6 +634,25 @@ function $RouteProvider() {
646634
}
647635

648636

637+
function getTemplateFor(route) {
638+
var template, templateUrl;
639+
if (angular.isDefined(template = route.template)) {
640+
if (angular.isFunction(template)) {
641+
template = template(route.params);
642+
}
643+
} else if (angular.isDefined(templateUrl = route.templateUrl)) {
644+
if (angular.isFunction(templateUrl)) {
645+
templateUrl = templateUrl(route.params);
646+
}
647+
if (angular.isDefined(templateUrl)) {
648+
route.loadedTemplateUrl = $sce.valueOf(templateUrl);
649+
template = $templateRequest(templateUrl);
650+
}
651+
}
652+
return template;
653+
}
654+
655+
649656
/**
650657
* @returns {Object} the current active route, by matching it against the URL
651658
*/

0 commit comments

Comments
 (0)