aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVojta Jina2012-03-30 13:40:19 -0700
committerVojta Jina2012-04-03 10:10:44 -0700
commit5f70d615a5f7e102424c6adc15d7a6f697870b6e (patch)
tree791ce11e20caaf40dc9297fbc8863d604de2fd4d /src
parent06d0955074f79de553cc34fbf945045dc458e064 (diff)
downloadangular.js-5f70d615a5f7e102424c6adc15d7a6f697870b6e.tar.bz2
refactor(ngInclude): remove scope attribute
The purpose of allowing the scope to be specified was to enable the $route service to work together with ngInclude. However the functionality of creating scopes was in the recent past moved from the $route service to the ngView directive, so currently there is no valid use case for specifying the scope for ngInclude. In fact, allowing the scope to be defined can under certain circumstances lead to memory leaks. Breaks ngInclude does not have scope attribute anymore.
Diffstat (limited to 'src')
-rw-r--r--src/ng/directive/ngInclude.js70
1 files changed, 31 insertions, 39 deletions
diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js
index 90fd0b40..f1c836f0 100644
--- a/src/ng/directive/ngInclude.js
+++ b/src/ng/directive/ngInclude.js
@@ -15,8 +15,6 @@
*
* @param {string} ng-include|src angular expression evaluating to URL. If the source is a string constant,
* make sure you wrap it in quotes, e.g. `src="'myPartialTemplate.html'"`.
- * @param {Scope=} [scope=new_child_scope] optional expression which evaluates to an
- * instance of angular.module.ng.$rootScope.Scope to set the HTML fragment to.
* @param {string=} onload Expression to evaluate when a new partial is loaded.
*
* @param {string=} autoscroll Whether `ng-include` should call {@link angular.module.ng.$anchorScroll
@@ -78,8 +76,7 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
return {
restrict: 'EA',
compile: function(element, attr) {
- var srcExp = attr.ngInclude || attr.src,
- scopeExp = attr.scope || '',
+ var srcExp = attr.ngInclude || attr.src,
onloadExp = attr.onload || '',
autoScrollExp = attr.autoscroll;
@@ -87,45 +84,40 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
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);
+ var clearContent = function() {
+ if (childScope) {
+ childScope.$destroy();
+ childScope = null;
+ }
+
+ element.html('');
+ };
+
+ scope.$watch(srcExp, function(src) {
+ var thisChangeId = ++changeCounter;
+
+ if (src) {
+ $http.get(src, {cache: $templateCache}).success(function(response) {
+ if (thisChangeId !== changeCounter) return;
- function clearContent() {
- // if this callback is still desired
- if (newChangeCounter === changeCounter) {
if (childScope) childScope.$destroy();
- childScope = null;
- element.html('');
- }
- }
+ childScope = scope.$new();
+
+ element.html(response);
+ $compile(element.contents())(childScope);
+
+ if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) {
+ $anchorScroll();
+ }
- 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();
- }
- scope.$emit('$includeContentLoaded');
- scope.$eval(onloadExp);
- }
- }).error(clearContent);
- } else {
- clearContent();
- }
+ scope.$emit('$includeContentLoaded');
+ scope.$eval(onloadExp);
+ }).error(function() {
+ if (thisChangeId === changeCounter) clearContent();
+ });
+ } else clearContent();
});
};
}
- }
+ };
}];