diff options
| author | Misko Hevery | 2012-02-15 14:32:10 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-02-28 17:46:58 -0800 |
| commit | f6fb31e8ada50b32719fcb120ca2e1fcbac8d992 (patch) | |
| tree | f698a8f12d5e46307ac1b20ff3ba33a64dec1f8f /src/widgets.js | |
| parent | 21c725f1a12d1de758cab6e4c4fafc5c420eb565 (diff) | |
| download | angular.js-f6fb31e8ada50b32719fcb120ca2e1fcbac8d992.tar.bz2 | |
chore(ng:view): simplify, by taking advantage of new compiler features
Diffstat (limited to 'src/widgets.js')
| -rw-r--r-- | src/widgets.js | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/src/widgets.js b/src/widgets.js index e83d0505..613ae1b4 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -540,42 +540,37 @@ var ngNonBindableDirective = valueFn({ terminal: true }); var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$compile', function($http, $templateCache, $route, $anchorScroll, $compile) { return { - compile: function(element, attr) { - if (!element[0]['ng:compiled']) { - element[0]['ng:compiled'] = true; - - return function(scope, element, attrs) { - var changeCounter = 0; + terminal: true, + link: function(scope, element) { + var changeCounter = 0; - scope.$on('$afterRouteChange', function() { - changeCounter++; - }); + scope.$on('$afterRouteChange', function() { + changeCounter++; + }); - scope.$watch(function() {return changeCounter;}, function(newChangeCounter) { - var template = $route.current && $route.current.template; + scope.$watch(function() {return changeCounter;}, function(newChangeCounter) { + var template = $route.current && $route.current.template; - function clearContent() { - // ignore callback if another route change occured since - if (newChangeCounter == changeCounter) { - element.html(''); - } - } + function clearContent() { + // ignore callback if another route change occured since + if (newChangeCounter == changeCounter) { + element.html(''); + } + } - if (template) { - $http.get(template, {cache: $templateCache}).success(function(response) { - // ignore callback if another route change occured since - if (newChangeCounter == changeCounter) { - element.html(response); - $compile(element)($route.current.scope); - $anchorScroll(); - } - }).error(clearContent); - } else { - clearContent(); + if (template) { + $http.get(template, {cache: $templateCache}).success(function(response) { + // ignore callback if another route change occured since + if (newChangeCounter == changeCounter) { + element.html(response); + $compile(element.contents())($route.current.scope); + $anchorScroll(); } - }); - }; - } + }).error(clearContent); + } else { + clearContent(); + } + }); } }; }]; |
