Skip to content

Instantly share code, notes, and snippets.

@schmitch
Last active August 29, 2015 14:05
Show Gist options
  • Save schmitch/10ae22be266c39410327 to your computer and use it in GitHub Desktop.
Save schmitch/10ae22be266c39410327 to your computer and use it in GitHub Desktop.
$q.when(next).
then(function() {
if (next) {
var locals = angular.extend({}, next.resolve);
angular.forEach(locals, function(value, key) {
locals[key] = angular.isString(value) ?
$injector.get(value) : $injector.invoke(value, null, null, key);
});
return $q.all(locals);
}
}).
then(function(locals) {
if (next) {
var template, templateUrl;
if (angular.isDefined(template = next.template)) {
if (angular.isFunction(template)) {
template = template(next.params);
}
} else if (angular.isDefined(templateUrl = next.templateUrl)) {
if (angular.isFunction(templateUrl)) {
templateUrl = templateUrl(next.params);
}
templateUrl = $sce.getTrustedResourceUrl(templateUrl);
if (angular.isDefined(templateUrl)) {
next.loadedTemplateUrl = templateUrl;
template = $templateRequest(templateUrl);
}
}
if (angular.isDefined(template)) {
locals['$template'] = template;
}
return $q.all(locals);
}
}).
// after route change
then(function(locals) {
if (next == $route.current) {
if (next) {
next.locals = locals;
angular.copy(next.params, $routeParams);
}
$rootScope.$broadcast('$routeChangeSuccess', next, last);
}
}, function(error) {
if (next == $route.current) {
$rootScope.$broadcast('$routeChangeError', next, last, error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment