aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/directive/ngView.js
diff options
context:
space:
mode:
authorMisko Hevery2012-05-22 21:12:19 -0700
committerMisko Hevery2012-06-01 16:56:31 -0700
commit885fb0dd0743859a8985c23e4d0c1855a2be711e (patch)
tree96b03b26395d500c21e4044f7afb048c2a7cebe9 /src/ng/directive/ngView.js
parent4361efb03b79e71bf0cea92b94ff377ed718bad4 (diff)
downloadangular.js-885fb0dd0743859a8985c23e4d0c1855a2be711e.tar.bz2
feat($route): resolve local route promises
Resolve all promises on route before we fire $afterRouteChange which then renders the ngView.
Diffstat (limited to 'src/ng/directive/ngView.js')
-rw-r--r--src/ng/directive/ngView.js64
1 files changed, 28 insertions, 36 deletions
diff --git a/src/ng/directive/ngView.js b/src/ng/directive/ngView.js
index 7c737765..4924ed1a 100644
--- a/src/ng/directive/ngView.js
+++ b/src/ng/directive/ngView.js
@@ -112,8 +112,7 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c
restrict: 'ECA',
terminal: true,
link: function(scope, element, attr) {
- var changeCounter = 0,
- lastScope,
+ var lastScope,
onloadExp = attr.onload || '';
scope.$on('$afterRouteChange', update);
@@ -127,43 +126,36 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c
}
}
+ function clearContent() {
+ element.html('');
+ destroyLastScope();
+ }
+
function update() {
- var template = $route.current && $route.current.template,
- thisChangeId = ++changeCounter;
-
- function clearContent() {
- // ignore callback if another route change occured since
- if (thisChangeId === changeCounter) {
- element.html('');
- destroyLastScope();
- }
- }
+ var locals = $route.current && $route.current.locals,
+ template = locals && locals.$template;
if (template) {
- $http.get(template, {cache: $templateCache}).success(function(response) {
- // ignore callback if another route change occured since
- if (thisChangeId === changeCounter) {
- element.html(response);
- destroyLastScope();
-
- var link = $compile(element.contents()),
- current = $route.current,
- controller;
-
- lastScope = current.scope = scope.$new();
- if (current.controller) {
- controller = $controller(current.controller, {$scope: lastScope});
- element.contents().data('$ngControllerController', controller);
- }
-
- link(lastScope);
- lastScope.$emit('$viewContentLoaded');
- lastScope.$eval(onloadExp);
-
- // $anchorScroll might listen on event...
- $anchorScroll();
- }
- }).error(clearContent);
+ element.html(template);
+ destroyLastScope();
+
+ var link = $compile(element.contents()),
+ current = $route.current,
+ controller;
+
+ lastScope = current.scope = scope.$new();
+ if (current.controller) {
+ locals.$scope = lastScope;
+ controller = $controller(current.controller, locals);
+ element.contents().data('$ngControllerController', controller);
+ }
+
+ link(lastScope);
+ lastScope.$emit('$viewContentLoaded');
+ lastScope.$eval(onloadExp);
+
+ // $anchorScroll might listen on event...
+ $anchorScroll();
} else {
clearContent();
}