aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2012-03-04 00:53:45 -0800
committerVojta Jina2012-03-05 10:41:59 -0800
commitc2989f6cc6ea8be34101b9ab9bc25d14a2468e20 (patch)
treee831412004458783740f3718c36f9c6e6da8830e
parent4f797fe5f38cab06d1bb9c946cd39ce31aaa2483 (diff)
downloadangular.js-c2989f6cc6ea8be34101b9ab9bc25d14a2468e20.tar.bz2
fix(ng-include): Compile only content
-rw-r--r--src/widgets.js82
-rw-r--r--test/widgetsSpec.js18
2 files changed, 58 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();
+ }
+ });
+ };
}
}
}];
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index f75d81c2..3d2f0a56 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -245,6 +245,24 @@ describe('widget', function() {
}));
+ it('should compile only the content', inject(function($compile, $rootScope, $templateCache) {
+ // regression
+
+ var onload = jasmine.createSpy('$contentLoaded');
+ $rootScope.$on('$contentLoaded', onload);
+ $templateCache.put('tpl.html', [200, 'partial {{tpl}}', {}]);
+
+ element = $compile('<div><div ng:repeat="i in [1]">' +
+ '<ng:include src="tpl"></ng:include></div></div>')($rootScope);
+ expect(onload).not.toHaveBeenCalled();
+
+ $rootScope.$apply(function() {
+ $rootScope.tpl = 'tpl.html';
+ });
+ expect(onload).toHaveBeenCalledOnce();
+ }));
+
+
describe('autoscoll', function() {
var autoScrollSpy;