diff options
Diffstat (limited to 'src/ng/directive/ngView.js')
| -rw-r--r-- | src/ng/directive/ngView.js | 64 | 
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();          } | 
