diff options
| author | Vojta Jina | 2011-11-04 18:33:12 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-11-30 14:49:03 -0500 | 
| commit | 16363d8000a484b428a16eb07d8bd0f19c4b4337 (patch) | |
| tree | 3d11a5a9c6ab0e455b2489f8ec6752bedf1ae0b5 /src | |
| parent | 92995bbce9877673f2642addd22fdf08d47bd39e (diff) | |
| download | angular.js-16363d8000a484b428a16eb07d8bd0f19c4b4337.tar.bz2 | |
refactor(ng:view, ng:include): pass cache instance into $http
Instead of doing all the stuff in these widgets (checking cache, etc..) we can rely on $http now...
Diffstat (limited to 'src')
| -rw-r--r-- | src/widgets.js | 59 | 
1 files changed, 19 insertions, 40 deletions
| diff --git a/src/widgets.js b/src/widgets.js index 861e61bf..c89f4179 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -112,18 +112,6 @@ angularWidget('ng:include', function(element){              useScope = scope.$eval(scopeExp),              fromCache; -        function updateContent(content) { -          element.html(content); -          if (useScope) { -            childScope = useScope; -          } else { -            releaseScopes.push(childScope = scope.$new()); -          } -          compiler.compile(element)(childScope); -          $autoScroll(); -          scope.$eval(onloadExp); -        } -          function clearContent() {            childScope = null;            element.html(''); @@ -133,16 +121,17 @@ angularWidget('ng:include', function(element){            releaseScopes.pop().$destroy();          }          if (src) { -          if ((fromCache = $templateCache.get(src))) { -            scope.$evalAsync(function() { -              updateContent(fromCache); -            }); -          } else { -            $http.get(src).on('success', function(response) { -              updateContent(response); -              $templateCache.put(src, response); -            }).on('error', clearContent); -          } +          $http.get(src, {cache: $templateCache}).on('success', function(response) { +            element.html(response); +            if (useScope) { +              childScope = useScope; +            } else { +              releaseScopes.push(childScope = scope.$new()); +            } +            compiler.compile(element)(childScope); +            $autoScroll(); +            scope.$eval(onloadExp); +          }).on('error', clearContent);          } else {            clearContent();          } @@ -586,30 +575,20 @@ angularWidget('ng:view', function(element) {          var template = $route.current && $route.current.template,              fromCache; -        function updateContent(content) { -          element.html(content); -          compiler.compile(element)($route.current.scope); -        } -          function clearContent() {            element.html('');          }          if (template) { -          if ((fromCache = $templateCache.get(template))) { -            scope.$evalAsync(function() { -              updateContent(fromCache); -            }); -          } else { -            // xhr's callback must be async, see commit history for more info -            $http.get(template).on('success', function(response) { -              // ignore callback if another route change occured since -              if (newChangeCounter == changeCounter) -                updateContent(response); -              $templateCache.put(template, response); +          // xhr's callback must be async, see commit history for more info +          $http.get(template, {cache: $templateCache}).on('success', function(response) { +            // ignore callback if another route change occured since +            if (newChangeCounter == changeCounter) { +              element.html(response); +              compiler.compile(element)($route.current.scope);                $autoScroll(); -            }).on('error', clearContent); -          } +            } +          }).on('error', clearContent);          } else {            clearContent();          } | 
