diff options
| author | Vojta Jina | 2012-03-04 00:53:45 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-03-05 10:41:59 -0800 |
| commit | c2989f6cc6ea8be34101b9ab9bc25d14a2468e20 (patch) | |
| tree | e831412004458783740f3718c36f9c6e6da8830e /src | |
| parent | 4f797fe5f38cab06d1bb9c946cd39ce31aaa2483 (diff) | |
| download | angular.js-c2989f6cc6ea8be34101b9ab9bc25d14a2468e20.tar.bz2 | |
fix(ng-include): Compile only content
Diffstat (limited to 'src')
| -rw-r--r-- | src/widgets.js | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/src/widgets.js b/src/widgets.js index a32abb75..66ea7fef 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -69,51 +69,49 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile' var srcExp = attr.src, scopeExp = attr.scope || '', autoScrollExp = attr.autoscroll; - if (!element[0]['ng:compiled']) { - element[0]['ng:compiled'] = true; - return function(scope, element, attr){ - var changeCounter = 0, - childScope; - - function incrementChange() { changeCounter++;} - scope.$watch(srcExp, incrementChange); - scope.$watch(function() { - var includeScope = scope.$eval(scopeExp); - if (includeScope) return includeScope.$id; - }, incrementChange); - scope.$watch(function() {return changeCounter;}, function(newChangeCounter) { - var src = scope.$eval(srcExp), - useScope = scope.$eval(scopeExp); - - function clearContent() { - // if this callback is still desired - if (newChangeCounter === changeCounter) { - if (childScope) childScope.$destroy(); - childScope = null; - element.html(''); - } + + return function(scope, element, attr) { + var changeCounter = 0, + childScope; + + function incrementChange() { changeCounter++;} + scope.$watch(srcExp, incrementChange); + scope.$watch(function() { + var includeScope = scope.$eval(scopeExp); + if (includeScope) return includeScope.$id; + }, incrementChange); + scope.$watch(function() {return changeCounter;}, function(newChangeCounter) { + var src = scope.$eval(srcExp), + useScope = scope.$eval(scopeExp); + + function clearContent() { + // if this callback is still desired + if (newChangeCounter === changeCounter) { + if (childScope) childScope.$destroy(); + childScope = null; + element.html(''); } + } - if (src) { - $http.get(src, {cache: $templateCache}).success(function(response) { - // if this callback is still desired - if (newChangeCounter === changeCounter) { - element.html(response); - if (childScope) childScope.$destroy(); - childScope = useScope ? useScope : scope.$new(); - $compile(element)(childScope); - if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { - $anchorScroll(); - } - scope.$emit('$contentLoaded'); + if (src) { + $http.get(src, {cache: $templateCache}).success(function(response) { + // if this callback is still desired + if (newChangeCounter === changeCounter) { + element.html(response); + if (childScope) childScope.$destroy(); + childScope = useScope ? useScope : scope.$new(); + $compile(element.contents())(childScope); + if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { + $anchorScroll(); } - }).error(clearContent); - } else { - clearContent(); - } - }); - }; - } + scope.$emit('$contentLoaded'); + } + }).error(clearContent); + } else { + clearContent(); + } + }); + }; } } }]; |
